提及的用户的角色未更改

时间:2020-06-04 22:07:03

标签: javascript discord.js

当工作人员对用户时间@mute进行静音时,它应该赋予Muted角色并带走Speaker角色,但这并不会发生,而是发生其他所有事情,并且角色没有被赋予或移走。

const Discord = require('discord.js');
const bot = new Discord.Client();
const ms = require('ms');


const token = '';

const PREFIX = '!';


bot.on('ready', () => {
    console.log('This bot is active!');
})

bot.on('message', message => {
    let args = message.content.substring(PREFIX.length).split(" ");

    switch (args[0]) {
        case 'mute':
            if(!message.member.hasPermission("MUTE_MEMBERS")) return message.reply("You cannot run this command");
            let mperson = message.guild.member(message.mentions.users.first() || message.guild.members.cache.get(args[1]));
            if(!mperson) return  message.reply("I cannot find the user " + mperson)

            var mainrole = message.guild.roles.cache.get("718166462862196777");
            var muterole = message.guild.roles.cache.get("717606607910993930");


            if(!muterole) return message.reply("Couldn't find the mute role.")


            let time = args[2];
            if(!time){
                return message.reply("You didnt specify a time!");
            }

            mperson.roles.add(mainrole).catch(console.error)
            mperson.roles.remove(muterole).catch(console.error);


            message.channel.send(`${mperson.user} has now been muted for ${ms(ms(time))}`)

            setTimeout(function(){

                mperson.roles.add(mainrole)
                mperson.roles.remove(muterole);
                console.log(muterole)
                message.channel.send(`${mperson.user} has been unmuted.`)
            }, ms(time));



        break;
    }


});



bot.login(token);

我想从提到的播放器中添加和删除的角色没有改变,我可以通过任何方式解决此问题?

1 个答案:

答案 0 :(得分:0)

我将mperson.roles.add(mainrole).catch(console.error)更改为mperson.roles.add("717631710761844757").catch(console.error),现在一切正常。这是discord.js v12。