![](/img/trans.png)
[英]How to remove all roles and add one role on discord bot, and then remove the added role and restore previous roles
[英]Command to remove all roles and add specific role to mentioned user
我希望创建一个命令,其中提到的用户将删除其所有角色并添加一个特定角色。 我在权限和公会语法方面遇到了一些困难。
我得到的当前代码是:
name: 'megabean',
description: 'makes Craig megabean people',
execute(message, args){
let guild = client.guilds.cache.get(guildId);
message.channel.send(`${message.author} has **MEGABEANED** ${args [0]}. Say goodbye to your perms
**Reason for MEGABEAN:** ${args.splice(1).join(" ")} `)
.then(guild.roles.set([]))
.then(guild.roles.add(['741934348273451032']))
}
}
目前,虽然我有 const client = new Discord.Client(); ,但没有定义客户端。 在我的 main.js 文件中
我只是在寻找有关如何更好地处理此任务的一些信息。 对不起,如果我可能看起来有些准备不足,到目前为止研究还没有让我走得太远......
这是因为您没有使用当前客户端而是创建一个新实例,我建议您将现有客户端作为函数参数传递给它(使用execute(message, args, client)
,您也可以再次登录此文件但我会小心,因为它可能会产生不必要的副作用。您是否还需要帮助来删除角色?
编辑:删除角色:
message.member.roles.remove(message.member.roles); //remove all
message.member.roles.add(message.guild.roles.cache.get("role ID here")); //add the specific role
就这样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.