0

我已经在 js 上构建了这个消息。如果您将机器人标记为用户以添加消息+标记该人,我想添加一个条件,否则只是发送正常消息。

我遇到的问题是 user_mention 的正确变量是什么。我找到了不同的方法,但无法使其工作。

DiscordClient.on('message', message => {
  const msg = message.content.toLowerCase();
  const mention = message.mentions.users;

  if (msg === "yubnub") {
    if (mention == null){
      message.channel.send('YUB NUB!! YUB NUB!! Grrrrr!!');
    } else {
      message.channel.send('YUB NUB!! YUB NUB!! Grrrrr!! ' + ${@user_mention})
    }
  }

});
4

3 回答 3

1

谢谢@boris 和@Adrian。最终代码如下所示:

if (msg.startsWith("yubjub")) {
const mention = message.mentions.members;

if (mention.size === 0){

  message.channel.send('YUB NUB!! YUB NUB!! Grrrrr!!);

} else {
    const mentionUser = mention.first().user;

    message.channel.send('YUB NUB!! YUB NUB!! Stab Stab Stab <@' + mentionUser.id + '> !!');

}

}

于 2020-04-06T14:51:13.343 回答
0

I think mention is an array of users. So you can do:

for (const user of mention) {
    message.channel.send('YUB NUB!! YUB NUB!! Grrrrr!! @' + user.username)
}
于 2020-04-06T08:39:35.293 回答
0

尝试 :

const mention = message.mentions.users.first();

资料来源:https ://anidiots.guide/first-bot/command-with-arguments#grabbing-mentions

于 2020-04-06T10:10:17.890 回答