client.on("message", (message) => {
if (message.member.hasPermission(["KICK_MEMBERS", "BAN_MEMBERS"])) {
if (message.content.startsWith(`${prefix}kick`)) {
let member = message.mentions.members.first();
if(!member) return message.channel.send('Cannot find this member');
member.kick().then((member) => {
message.channel.send("```" + member.displayName + " has been kicked ```");
});
}
}
这是禁止踢的代码。^^
答案 0 :(得分:0)
您想在client.on("message", (message)
块的内部中放置命令。
我将在您的代码中以它为例:
client.on('message', message =>{
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if(command === 'ping'){
client.commands.get('ping').execute(message, args);
}
// Kick start
if (command === 'kick') {
// Only check if the command caller has permission,
// AFTER the command is called, not before.
if (message.member.hasPermission(["KICK_MEMBERS", "BAN_MEMBERS"])) {
// Define which member needs to get kicked by grabbing the first mentioned guild member
let member = message.mentions.members.first();
// If the tagged member is not found in your guild,
// throw this message
if(!member) return message.channel.send('Cannot find this member');
// Proceed to kick the member
member.kick().then((member) => {
message.channel.send("```" + member.displayName + " has been kicked ```");
});
}
});
我希望这能回答您的问题。如果尚未检查discordjs文档here,请检查它们。他们提供了有关设置机器人的不错的教程。