简体   繁体   English

提到的用户的角色没有改变

[英]roles are not being changed for the mentioned user

When a staff does,mute @user time, it should give the role Muted and take away the role Speaker, this does not happen though.当工作人员将@user 静音时,它应该赋予角色静音并取消角色发言人,但这不会发生。 instead everything else happens and the roles are not given or taken away.相反,其他一切都发生了,角色没有被赋予或被剥夺。

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);

The roles that I want to add and remove from the mentioned player do not change, any way that I can fix this?我想从提到的玩家中添加和删除的角色没有改变,我有什么办法可以解决这个问题?

I changed mperson.roles.add(mainrole).catch(console.error) to mperson.roles.add("717631710761844757").catch(console.error) and now everything works.我将mperson.roles.add(mainrole).catch(console.error)更改为mperson.roles.add("717631710761844757").catch(console.error)现在一切正常。 This is discord.js v12.这是 discord.js v12。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM