我如何检测提到的成员并使用 discord 机器人为他们分配角色? (Javascript)

How do I detect a mentioned member and assign a role to them with a discord bot? (Javascript)

我正在尝试设置一个 Discord 机器人,它会在用户键入命令后为用户提供一个名为 'Suspended' 的预制角色。我希望命令是 !suspend @user length 但我不确定如何判断是否提到了用户。

const Commando = require('discord.js-commando');
const bot = new Commando.Client();
const TOKEN = 'redacted'

bot.registry.registerGroup('simple', 'Simple');
bot.registry.registerDefaults();
bot.registry.registerCommandsIn(__dirname + '/commands');


bot.on('message', function(message){
    if(message.content == 'testk.1')
    {
        message.channel.sendMessage('Hi ' + message.author + ' nab.');
    }
    if(message.content == 'testk.2')
    {
        message.member.send("Nabwoo XD");
    }
    if(message.content == '!suspend', mentionsMember) //This is the part im 
having an issue on
    {
         message.channel.sendMessage('works');
    }
});
bot.on('ready',function(){
console.log("Ready");
})
bot.login(TOKEN);

如何将名为 'Suspended' 的角色分配给消息中提到的用户?

有很多方法可以解决这个问题。下面只是一种方法,将字符串按空格拆分为数组,并查看是否有 3 个部分并确保第一部分为 !suspend,第二部分以 @ 开头。当然你可以根据自己的需要做的更结实一些。

    if(message.content.split(" ").length === 3 && message.content.split(" ")[0] == '!suspend' && message.content.split(" ")[1].startsWith("@"))
    {
         var mentionsMember = message.content.split(" ")[1]; // 2nd item in array when text is split by spaces, (ex. `@user`)
         message.channel.sendMessage('works');
    }