Discord.js机器人在提及时会做出回应 [英] Discord.js bot responds when mentioned

查看:60
本文介绍了Discord.js机器人在提及时会做出回应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让我的discord.js机器人在ping通时发送一条消息.我不确定如何执行此操作,因此我引用了以下代码:

I'm trying to make my discord.js bot send a message when it is pinged. I was unsure how to do this so I referred to this code:

client.on('message', message => {
    if (message.content === '<@745648345216712825>') {
        message.channel.send('Message Here');
    }
});

但是,这不起作用.

此外,当某人提及某个特定用户时,例如当用户在机器人响应的消息中的任何地方提到我时,我的机器人是否有响应?如果是,您能告诉我怎么做吗?

Also, is it possible that my bot responds when a person mentions a specific user for example if I am mentioned by the user anywhere in a message the bot responds? If yes, can you show me how to do it?

推荐答案

Message 具有一个名为 mentions ,其中包含消息中提到的所有渠道,成员,角色和用户.您可以使用方法 .has(data, [options]) MessageMentions 来查看是否提到了您的漫游器.

Message has a property called mentions, which contains all the channels, members, roles, and users mentioned in the message. You can use the method .has(data, [options]) of MessageMentions to see if your bot was mentioned.

client.on("message", message => {
    if (message.author.bot) return false;

    if (message.content.includes("@here") || message.content.includes("@everyone")) return false;

    if (message.mentions.has(client.user.id)) {
        message.channel.send("Hello there!");
    };
});

这篇关于Discord.js机器人在提及时会做出回应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆