简体   繁体   English

DiscortJS 机器人在提及特定用户的频道上发回消息

[英]DiscortJS bot send a message back on the channel mentioning a specific user

I have build this message on js.我已经在 js 上构建了这个消息。 And i want to add a condition if you tag an user the bot to add the message + tag that person otherwise just to send a normal message.如果您将机器人标记为用户以添加消息+标记该人,我想添加一个条件,否则只是发送普通消息。

The issue that I have is what is the right variable for user_mention.我遇到的问题是 user_mention 的正确变量是什么。 I found different ways, but couldn't make it to work.我找到了不同的方法,但无法使其工作。

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})
    }
  }

});

Thank you @boris and @Adrian.谢谢@boris 和@Adrian。 The final code looks like this:最终代码如下所示:

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

}

} }

I think mention is an array of users .我认为mention的是一组用户 So you can do:所以你可以这样做:

for (const user of mention) {
    message.channel.send('YUB NUB!! YUB NUB!! Grrrrr!! @' + user.username)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 discord 机器人将消息发送到特定通道? - How to send message to a specific channel with discord bot? 使不和谐机器人发送消息特定通道 - make discord bot to send message specific channel 如何让我的 discord 机器人仅在用户开始输入特定频道时发送消息? - How can I make my discord bot only send a message if a user starts typing in a specific channel? Discord.js bot 无法将消息发送到特定通道 - Discord.js bot can't send message to specific channel JS-Discord Bot在MIDNIGHT的特定频道上发送消息 - JS - Discord Bot Send Message on specific channel AT MIDNIGHT 无论在任何频道中发出命令,我如何通过机器人向特定频道发送消息 - How do i send a message to a specific channel by the bot no matter command is issued in any channel 我希望我的不和谐机器人向用户提供的文本房间发送随机消息 [按频道 ID 或频道名称] - I want my discord bot to send a random message to a text room given by user [by channel id or channel name] 检查用户是否可以在特定频道 discord.js 中发送消息 - Check if a user can send message in a specific channel discord.js 如何将消息发送到特定频道? - How to send a message to a specific channel? 有没有办法在 bot.on(&quot;ready&quot;) 函数中向特定用户发送消息? - Is there a way to send a message to a specific user in the bot.on("ready") function?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM