该命令的踢出部分正常工作,然后正确发送一条消息,称其已踢出所提到的人。但是,我希望机器人发送一条消息,说如果没有提到用户,则需要提及一个用户。如果尝试使用该机器人的玩家没有踢某人的适当权限,或者该机器人无法踢出用户试图使用该机器人踢的人,我也希望该机器人发送一条消息。
这是我要执行的操作的代码。
Crashbot.on('message', message => {
if (message.member.hasPermission("KICK_MEMBERS")) {
if (message.content.startsWith(prefix + 'kick')) {
const user = message.mentions.users.first();
if (user) {
const member = message.guild.member(user);
if (member) {
member.kick('optional reason that will display in the audit logs')
.then(() => {
// We let the message author know we were able to kick the person
message.reply(`Successfully kicked ${user.tag}`);
})
.catch(err => {
message.reply('I was unable to kick that user');
console.error(err);
});
} else {
message.reply("You need to mention a user to kick");
}
}
}
}
});
答案 0 :(得分:-1)
那是我用的那个。它会检查您是否一开始就提到了任何内容,如果找不到用户,就会发出警告消息,如果您没有踢人的权限,也不能踢人,则它不会起作用它会告诉你他不能踢他。另外,您可以提供后踢的可选原因。
用法示例:!kick @ Apolko24用法错误
const kUser = message.guild.member(message.mentions.users.first());
if (!args[0]) return message.channel.send('Please mention someone');
if (!kUser) return message.channel.send(`I can't find ${args[0]}`);
if (!message.member.hasPermission('KICK_MEMBERS')) return message.channel.send("You can't kick users");
if (kUser.hasPermission('MANAGE_GUILD')) return message.channel.send("That user can't be kicked");
const kReason = args.join(" ").slice(22);
if (kReason) {
const kickEmbed = new MessageEmbed()
.setTitle("Kick")
.setColor(0xbbffff)
.addField("Kicked user:", `${kUser}`)
.addField("Kicked by:", `${message.author}`)
.addField("Reason", kReason)
message.guild.member(kUser).kick();
message.channel.send(kickEmbed);
} else {
const kickEmbed = new MessageEmbed()
.setTitle("Kick")
.setColor(0xbbffff)
.addField("Kicked user:", `${kUser}`)
.addField("Kicked by:", `${message.author}`)
message.guild.member(kUser).kick();
message.channel.send(kickEmbed);
}
(您必须将其放入if(message.content.startsWith(prefix +'kick'))语句中)