我的 kick 命令让服务器中的任何人都可以踢某人
- 作者: 一生霸气帝王道
- 来源: 51数据库
- 2022-10-25
问题描述
我的 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');
您还可以通过某人拥有的角色来限制访问,我敦促您阅读 这个现有的答案
推荐阅读
热点文章
检查拆分键盘
0
带有“上一个"的工具栏和“下一个"用于键盘输入AccessoryView
0
Activity 启动时显示软键盘
0
UIWebView 键盘 - 摆脱“上一个/下一个/完成"酒吧
0
在 iOS7 中边缘滑动时,使键盘与 UIView 同步动画
0
我的 iOS 应用程序中的键盘在 iPhone 6 上太高了.如何在 XCode 中调整键盘的分辨率?
0
android:inputType="textEmailAddress";- '@' 键和 '.com' 键?
0
禁用 iPhone 中键盘的方向
0
Android 2.3 模拟器上的印地语键盘问题
0
keyDown 没有被调用
0
