首页 > 解决方案 > 不同的用户 ID [discord.js]

问题描述

所以我在一个不和谐的机器人中工作,我想在一个命令中添加不同的用户 ID,但现在它不起作用。代码如下所示:

if (message.author.id !== '513773028606476308', '749446086493470751') return message.channel.send("no")

标签: javascript

解决方案


我假设您希望一个命令只具有特定 ID 的用户运行。因此,该if语句将在某种处理该特定命令的函数中。您的答案是将 if 语句更改为

if (!['513773028606476308', '749446086493470751'].includes(message.author.id)){return message.channel.send("no")}

但是,最好的解决方案是首先拥有这些特殊 ID 的数组,例如

let allowed=['513773028606476308', '749446086493470751']
if (!allowed.includes(message.author.id)){return message.channel.send("no")}

推荐阅读