javascript - DiscortJS 机器人在 channel 上发回一条消息,提及特定用户

标签 javascript bots discord discord.js mention

我已经在 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})
    }
  }

});

最佳答案

谢谢@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 + '> !!');

}

}

关于javascript - DiscortJS 机器人在 channel 上发回一条消息,提及特定用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61055865/

相关文章:

javascript - 使用正则表达式以逗号分隔的 Rails 自动完成标签

python - 无法通过 http.client 正确重新连接

javascript - 如何让机器人对自己的消息使用react?

python - 使用 on_application_command_error() 与 @command.error 进行回溯处理

javascript - 我正在尝试将数据从单元格范围发送到不和谐的聊天 channel

javascript - 避免在列表中填充

javascript - 在 Chrome 上的 Web Serial API 中获取连接设备的名称

javascript - 如何创建 channel 然后找到ID

javascript - 需要帮助将小数四舍五入 Javascript

php - ip blocker 类阻止 "crawl-66-249-76-64.googlebot.com",这是正确的吗?