我要发出一条命令,使该漫游器仅回复特定的用户ID。但是我很困惑如何做到这一点(仅供参考,我是JS的新手)
const userID = '<@4608164XXX93150209>'
bot.on("message", function(message){
if(!message.author === userID)
{
if(message.content === 'psst')
{
message.channel.send('Hello there!');
}
}});
答案 0 :(得分:1)
那只是一个字符串,而不是行会成员ID。 在这里做。
const userId = message.guild.members.find(m => m.id === "USER ID HERE");
答案 1 :(得分:0)
回复有点晚,但是我有同样的问题,我使用msg.sender
而不是msg.sender
const userID = "4608164XXX93150209"
bot.on("message", function(message){
if(!message.sender === userID)
{
if(message.content === 'psst')
{
message.channel.send('Hello there!');
}
}});
请注意,msg.sender
是一个字符串,而不是数字
答案 2 :(得分:0)
您可以使用message.author.id
获取消息的作者ID,然后应用您的逻辑。
let authorId = message.author.id;
//check author id here...
let mentionString = '<@!'+authorId+'>';
message.channel.send(mentionString+' pong');
答案 3 :(得分:0)
我看到人们在这里写了不同的答案,所以请写下您应该使用的特定代码。
const userID = "The_user's_id";
bot.on("message", function(message) {
if (message.author.id === userID) {
message.react('emoji name or id');
}
});
注意:要找到用户的ID,只需右键单击该用户,然后按“复制ID”即可。
答案 4 :(得分:-1)
那不是您的用户ID。如果启用了开发人员模式(用户设置->外观->开发人员模式),然后右键单击您的名称并单击“复制ID”,则可以找到您的用户ID。
该ID应该是一长串数字,而您只需要将其粘贴为ID。不要添加@或任何<>或其他任何内容。 ID的示例是198500238384693248