久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Discord.js 禁止/踢命令可供所有用戶使用.我怎樣才

Discord.js ban/kick commands available to all users. How can I fix this?(Discord.js 禁止/踢命令可供所有用戶使用.我怎樣才能解決這個問題?)
本文介紹了Discord.js 禁止/踢命令可供所有用戶使用.我怎樣才能解決這個問題?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在制作自己的 Discord Bot,因為我不相信更大的(Dyno、Hime、NosoBot 等)而且我的機器人已經完成了.唯一的問題是我的代碼允許所有成員使用這些命令.我只希望人們能夠使用他們有權使用的功能.該代碼有效,但我怎樣才能讓它只允許有權踢/禁止的人?

I'm making my own Discord Bot because I don't trust the bigger ones (Dyno, Hime, NosoBot, etc.) And my bot is pretty much done. The only problem is that my code allows all members to use these commands. I only want people to be able to use the functions they have permissions to. The code works, but how can I make it allow only people with permission to kick/ban?

if (msg.content.startsWith("$kick ")) {
    if (msg.mentions.members.first()) {
        msg.mentions.members.first.kick().then((member) => {
            msg.channel.send(":wave: " + member.displayName + " has been successfully kicked :point_right: ");
        }).catch(() => {
            msg.channel.send("I do not have permissions to do this");
        });
    }
}else if (msg.content.startsWith("$ban ")) {
   if (!message.member.hasPermission("MANAGE_MESSAGES")) return;
    if (msg.mentions.members.first()) {
        msg.mentions.members.first.ban().then((member) => {
            msg.channel.send(":wave: " + member.displayName + " has been successfully banned :point_right: ");
        }).catch(() => {
            msg.channel.send("I do not have permissions to do this");
        });
    }
}

推薦答案

KICK_MEMBERS"權限告訴您他們是否有權踢成員,因此得名.

The "KICK_MEMBERS" permission tells you if they have the permission to kick members, hence the name.

BAN_MEMBERS"權限告訴您他們是否有權禁止成員,因此名稱.

The "BAN_MEMBERS" permission tells you if they have the permission to ban members, hence the name.

你的踢腿命令:

if (msg.member.hasPermission("KICK_MEMBERS")) {
    if (msg.members.mentions.first()) {
        try {
            msg.members.mentions.first().kick();
        } catch {
            msg.reply("I do not have permissions to kick " + msg.members.mentions.first());
        }
    } else {
        msg.reply("You do not have permissions to kick " + msg.members.mentions.first());
    }
}

你的禁令命令:

if (msg.member.hasPermission("BAN_MEMBERS")) {
    if (msg.members.mentions.first()) {
        try {
            msg.members.mentions.first().ban();
        } catch {
            msg.reply("I do not have permissions to ban" + msg.members.mentions.first());
        }
    } else {
        msg.reply("You do not have permissions to ban" + msg.members.mentions.first());
    }
}

trycatch 的原因確保如果機器人沒有權限踢或禁止該用戶,它不會導致錯誤.

The reason for the try and catch ensures that if the bot does not have permissions to kick or ban that user, it will not cause an error.

另一個說明:

您不必創建另一個 bot.on('message') 事件.相反,只需使用 elseif

You do not have to create another bot.on('message') event. Instead just use an elseif

這篇關于Discord.js 禁止/踢命令可供所有用戶使用.我怎樣才能解決這個問題?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復必須使用導入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務器時的歡迎消息)
主站蜘蛛池模板: 成年人在线电影 | 国产高清美女一级a毛片久久w | 亚洲人免费视频 | 爱爱综合网 | japanhd成人 | 中文一区二区 | 好姑娘影视在线观看高清 | 国产aa| 99久久婷婷国产综合精品 | 日本一区二区三区四区 | 亚洲免费高清 | 蜜桃特黄a∨片免费观看 | 超碰在线人 | 黄色网址在线免费观看 | 亚洲欧美在线观看 | 欧美三区在线观看 | 国产精品久久久久久久久久妇女 | av一区二区在线观看 | 精品一区二区三区中文字幕 | 久久久国产网站 | 国产又爽又黄的视频 | 精品视频免费 | 日本激情视频中文字幕 | 天天操夜夜爽 | 国产在线精品一区二区三区 | 在线免费观看成人 | 亚洲国产一区二区视频 | 超碰欧美 | 韩国理论电影在线 | 国产成人精品一区二区三区四区 | 国产精品无码久久久久 | 黄色在线免费观看 | 日韩国产一区二区三区 | 男女在线免费观看 | 免费a国产 | 国产精品久久久久久中文字 | 在线天堂免费中文字幕视频 | 日韩欧美大片 | 黄瓜av | 日韩在线视频免费观看 | 亚洲精品自在在线观看 |