【发布时间】:2021-07-11 13:52:27
【问题描述】:
我想知道是否可以阻止特定用户使用机器人,例如如果用户 b 在 config.json 的黑名单中,则不能使用任何命令。谢谢
【问题讨论】:
标签: node.js discord.js
我想知道是否可以阻止特定用户使用机器人,例如如果用户 b 在 config.json 的黑名单中,则不能使用任何命令。谢谢
【问题讨论】:
标签: node.js discord.js
这是你可以使用的东西
const bannedUsers = ['userid1', 'userid2', 'userid3'];
client.on('message', msg => {
if(bannedUsers.includes(msg.author.id)) return;
//command execution code here
})
你必须把它放在你所有的client.on('message')听众中。
【讨论】:
你没有显示任何代码,但你可以尝试这样的处理命令的地方..
//when bot receives a message
if (message.author.id === 'blacklisted ids'){
return;
} else {
//process commands
}
【讨论】:
foreach 对照数组中每个列入黑名单的 id 检查 message.author.id。
Array.prototype.includes 让它更快