问题描述
我的 discord 机器人需要我的 kick 命令才能为版主和管理员工作.有没有人有更多的编码可以让它只有模组或管理员可以踢?
I need my kick command for my discord bot only be able to work for moderators and *****s. Does anyone have any more coding that could make it so only mods or *****s could kick?
我对 kick 命令的编码:
My coding for the kick command:
client.on('message', (message) => { if (!message.guild) return; if (message.content.startsWith('!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(() => { message.reply(`Successfully kicked ${user.tag}`); }) .catch((err) => { message.reply('I was unable to kick the member'); console.error(err); }); } else { message.reply("That user isn't in this guild!"); } } else { message.reply("You didn't mention the user to kick!"); } } });
推荐答案
你可以使用 GuildMember.hasPermission 检查用户是否有一定的权限.您可以在 这里,虽然我认为在这种情况下你会想要使用 KICK_MEMBERS.
You can use GuildMember.hasPermission to check if a user has a certain permission. You can see the valid permission flags here, although I think you'll want to use KICK_MEMBERS in this case.
if (!message.member.hasPermission('KICK_MEMBERS')) return message.channel.send('Insufficient Permissions');
您还可以通过某人拥有的角色来限制访问,我敦促您阅读 这个现有的答案