是否可以让我的 discord.js 机器人忽略某些用户?更像是通过命令将它们添加到 json 文件并忽略所有这些
Is it possible to make my discord.js bot ignore certain users? More like adding them to a json file by a command and ignoring all of them
如何让我的机器人在执行命令时忽略某些 用户?
我没有代码可以显示,因为我不知道从哪里开始,而且搜索后也没有找到任何东西。
如果您有一组 用户 ID 被列入执行命令的黑名单,您可以简单地执行以下操作:
const arrayOfUsersIds = ['8794328794879328794897', '789438729489732789', '764327969748632978'];
for (let i = 0; i < arrayOfUsersIds.length; i++) {
if (message.author.id === arrayOfUsersIds[i]) return message.reply('You are on the blacklist!');
};
只需将所有用户ID添加到这个名为arrayOfUsersIds
的数组中,所有这些用户将不再被允许执行命令。
你也可以对用户名做同样的事情! 只需将你不想在数组中执行命令的用户名添加到名为 arrayOfUsersnames
的数组中然后他们就不能再执行命令了!
const arrayOfUsersNames = ['Monkeyyy11', 'Tden', 'Zenoo'];
for (let i = 0; i < arrayOfUsersNames.length; i++) {
if (message.author.username.toLowerCase() === arrayOfUsersNames[i].toLowerCase()) return message.reply('You are on the blacklist!');
};
如何让我的机器人在执行命令时忽略某些 用户?
我没有代码可以显示,因为我不知道从哪里开始,而且搜索后也没有找到任何东西。
如果您有一组 用户 ID 被列入执行命令的黑名单,您可以简单地执行以下操作:
const arrayOfUsersIds = ['8794328794879328794897', '789438729489732789', '764327969748632978'];
for (let i = 0; i < arrayOfUsersIds.length; i++) {
if (message.author.id === arrayOfUsersIds[i]) return message.reply('You are on the blacklist!');
};
只需将所有用户ID添加到这个名为arrayOfUsersIds
的数组中,所有这些用户将不再被允许执行命令。
你也可以对用户名做同样的事情! 只需将你不想在数组中执行命令的用户名添加到名为 arrayOfUsersnames
的数组中然后他们就不能再执行命令了!
const arrayOfUsersNames = ['Monkeyyy11', 'Tden', 'Zenoo'];
for (let i = 0; i < arrayOfUsersNames.length; i++) {
if (message.author.username.toLowerCase() === arrayOfUsersNames[i].toLowerCase()) return message.reply('You are on the blacklist!');
};