繁体   English   中英

当特定用户被标记时,Discord 机器人会做出反应

[英]Discord bot reacts when specific user is tagged

我是编程新手,我正在尝试为我和我的朋友制作一个 Discord 机器人,现在我已经设置了两个命令,第一个工作正常,但第二个是问题所在。

client.on('message', msg => {
  if (msg.content === `@usertag#0001`) {
    msg.channel.send(`<@${msg.author.id}> <@${msg.author.id}> <@${msg.author.id}> <@${msg.author.id}> don't tag me`);
  }
});

所以它应该做的是,当特定用户被标记时,它会发送一条消息,从机器人发送的消息正在工作(它标记发送消息 3 次的用户,然后它说其他内容),但是机器人所在的部分识别标签不起作用。

我尝试通过放置 Discord id、使用完整的 @ 和其他东西,但它似乎不起作用。

为此,您可以使用message.mentions方法,例如,您可以如何使用它:

// For Discord V13 'message' is deprecated and
// will be removed in the future, use 'messageCreate' instead.
client.on("message", msg => {
    // Disable messages from bot to avoid endless loops / replies
    if(msg.author.bot === true) return;

    // Check if anyone is mentioned.
    // Skip @everyone mentions to be checked.
    if(msg.mentions.users.size > 0 && msg.mentions.everyone === false) {
        if(msg.mentions.users.find(user => user.id === "ENTER USER ID HERE")) {
            msg.channel.send(`<@${msg.author.id}> <@${msg.author.id}> <@${msg.author.id}> <@${msg.author.id}> don't tag me!`);
        }
    }
});

希望能帮到你! ! 我已经使用 Discord V13 对此进行了测试,我不确定这是否也适用于 Discord V12。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM