【发布时间】:2018-12-20 09:59:22
【问题描述】:
所以,标题简要说明了我想要什么。
当成员加入我的 Discord 服务器时,我希望机器人自动为他们分配用户角色。在此之前,我想验证机器人是否有权管理角色,到目前为止,我的代码中有以下内容。
/** Event will trigger when a user joins the server **/
bot.on("guildMemberAdd", function(member) {
if (!bot.user.hasPermission("MANAGE_ROLES")) {
var embed2 = new discord.RichEmbed()
.setTitle("Error")
.setDescription("The bot doesn't have the appropriate permissions to assign new members roles automatically.\nTo resolve this problem, go to **Server Settings** and then navigate to the **Roles** option. Next, click on **Bots**, and then click on the slider next to **Manage Roles** to activate it.")
.setColor("#3937a5")
bot.channels.get("466878539980079105").send(embed2);
} else {
member.addRole(member.guild.roles.find("name", "User"));
}
});
如果机器人没有权限,它将通过向#alert 频道发布警报来引起工作人员的注意。
但是,我尝试使用新的 Discord 帐户加入,它在控制台中报告 hasPermission 不是函数,然后停止。
对于如何解决此代码有什么建议吗?
【问题讨论】:
-
你在哪里找到了 hasPermission 方法?我在文档中找不到它。所以hasPermission不是函数是正确的
标签: javascript discord discord.js