本文介紹了我的 kick 命令讓服務器中的任何人都可以踢某人的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我的 discord 機器人需要我的 kick 命令才能為版主和管理員工作.有沒有人有更多的編碼可以讓它只有模組或管理員可以踢?
I need my kick command for my discord bot only be able to work for moderators and admins. Does anyone have any more coding that could make it so only mods or admins 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');
您還可以通過某人擁有的角色來限制訪問,我敦促您閱讀 這個現有的答案
這篇關于我的 kick 命令讓服務器中的任何人都可以踢某人的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!