Discord JS,回复某个用户ID

新手上路,请多包涵

我想发出一个命令,让机器人只回复某个用户 ID。但我很困惑如何做到这一点(仅供参考,我是 JS 的新手)

 const userID = '<@4608164XXX93150209>'

bot.on("message", function(message){
if(!message.author === userID)
{

if(message.content === 'psst')
    {
        message.channel.send('Hello there!');
    }
}});

原文由 Ad S.S 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 382
2 个回答

回复有点晚,但我有同样的问题,我使用了 msg.sender 而不是 msg.author

 const userID = "4608164XXX93150209"

bot.on("message", function(message){
if(!message.sender === userID)
{

if(message.content === 'psst')
{
    message.channel.send('Hello there!');
}
}});

请注意 msg.sender 是一个字符串而不是数字

原文由 aByteCurious 发布,翻译遵循 CC BY-SA 4.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”。

原文由 Harel 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Stack Overflow 翻译
子站问答
访问
宣传栏