我想通过“聊天”设置角色| Discord.js v12

时间:2020-11-01 09:27:07

标签: javascript discord.js

MuteUser = message.mentions.members.first();
MuteRole = message.guild.roles.cache.get("x")

我想像使用“ .rolemute @Muted”一样更改角色

2 个答案:

答案 0 :(得分:0)

您可以简单地定义静音角色:

var mutedRole = message.guild.roles.cache.get("x")

然后,如果您想通过消息进行更改:

var prefix = '.';
if (message.content.toLowerCase().startsWith(prefix + 'rolemute') { //when the command "rolemute" is said...
    let args = message.content.slice(prefix.length).trim().split(/ +/g); //split the message.
    if (!args[1]) return message.channel.send('You have not mentioned a new muted role.'); //if user did not mention a new role return a message.
    mutedRole = message.mentions.roles.first() || message.guild.roles.cache.get(args[1]); //define the new role.
    if (!mutedRole) return message.channel.send('I could not find the role you have specified.'); //If the role does not exist in the guild.
    message.channel.send(`Your muted role is now set to ${mutedRole}.`); //If the new muted role was successful.

答案 1 :(得分:0)

message.mentions返回MessageMentions类的实例。除了具有membersusers属性之外,它还具有channels,幸运的是,roles

const MuteRole = message.mentions.roles.first();