我一直在寻找从YouTube到Google的阻止命令的教程,但仍然找不到。
例如:!block @user
。该漫游器将不会响应被阻止的用户消息。我一直在研究discord.js库,但除User.block()
之外找不到其他库,但仅在使用用户帐户时可用。
答案 0 :(得分:0)
您可以使命令将目标的ID保存在数组中,然后忽略该消息(如果该消息来自该用户)。
// At the top of your code:
var blockedUsers = [];
// Inside you command
if (command == 'block') {
let user = message.mentions.users.first();
if (user && !blockedUsers.includes(user.id)) blockedUsers.push(user.id);
}
// When you want to check if the user is blocked, at the top of your client.on('message') event listener
client.on('message', message => {
if (blockedUsers.includes(message.author.id) || message.author.bot || /* all of your stuff that you want to ignore */) return;
// The rest of your code...
});
请注意,除非您将其存储在json文件或数据库中,否则每次重新启动bot都会重置该数组。
答案 1 :(得分:0)
您只需要做的是:
let blacklist = new Discord.MessageEmbed()
.setColor("#e31212")
.setDescription(
"ERROR: You are blacklisted in the database by the owner from using this command."
);
var blacklistarray =["", "", "", ""];// ID or ID(s) of user you wish to blacklist here
if (blacklistarray.includes(message.author.id))
return message.channel.send(blacklist);
这将从特定命令中阻止所需的用户。确保将其放在要从中将用户列入黑名单的命令的顶部。