简体   繁体   English

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

[英]Discord bot reacts when specific user is tagged

I'm new to programming and i'm trying to make a Discord bot for me and my friends, for now I have set up two commands, the first works fine, but the second one is the problem.我是编程新手,我正在尝试为我和我的朋友制作一个 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`);
  }
});

So what it should do is when a specific user is tagged it sends a message, the message sent from the bot is working (it tags the user who sent the message 3 times and then it says something else), but the part where the bot recognizes the tag doesn't work.所以它应该做的是,当特定用户被标记时,它会发送一条消息,从机器人发送的消息正在工作(它标记发送消息 3 次的用户,然后它说其他内容),但是机器人所在的部分识别标签不起作用。

I tried by putting the Discord id, using the full @, and other stuff, but it doesn't seem to work.我尝试通过放置 Discord id、使用完整的 @ 和其他东西,但它似乎不起作用。

For this you could use the message.mentions method, and here is how you could use it for example:为此,您可以使用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!`);
        }
    }
});

Hope this will help you!希望能帮到你! ! I have tested this with Discord V13, i'm not 100% sure if this will work on Discord V12 as well.我已经使用 Discord V13 对此进行了测试,我不确定这是否也适用于 Discord V12。

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

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