我一直在做这个静音命令,主要的是,它只是去除了主要角色。我希望它删除所有角色,只将角色静音,然后再次取消角色静音。 这是我尝试过的:
module.exports = {
name: `jail`,
description: "this is jail command!",
execute(message, args){
const member = message.mentions.users.first();
if(member){
const memberTarget = message.guild.members.cache.get(member.id);{
if (!message.member.hasPermission("MANAGE_MESSAGES")) return message.channel.send("You cant jail person because you are not staff/co owner/owner");
}
let mainRole = message.guild.roles.cache.get(`791144820810842163` , `794825576602533898` , `791144908240060426` , `791144966474563624` , `791145298072305685` , `791145926344966185` , `791146191336505414` , `791146355552682034` , `792565793568587796` , `795357387794939904` , `795358283623432213` , `798804993468530699` , `791146747367653387`)
let muteRole = message.guild.roles.cache.find(role => role.name === 'Jailed');
if (!args[1]) {
memberTarget.roles.remove(`791144820810842163` , `794825576602533898` , `791144908240060426` , `791144966474563624` , `791145298072305685` , `791145926344966185` , `791146191336505414` , `791146355552682034` , `792565793568587796` , `795357387794939904` , `795358283623432213` , `798804993468530699` , `791146747367653387`);
memberTarget.roles.add(muteRole.id);
message.channel.send(`<@${memberTarget.user.id}> has been Jailed`);
return
}
memberTarget.roles.remove(`791144820810842163` , `794825576602533898` , `791144908240060426` , `791144966474563624` , `791145298072305685` , `791145926344966185` , `791146191336505414` , `791146355552682034` , `792565793568587796` , `795357387794939904` , `795358283623432213` , `798804993468530699` , `791146747367653387`);
memberTarget.roles.add(muteRole.id);
message.channel.send(`<@${memberTarget.user.id}> has been Jailed for ${(ms(args[1]))}`);
setTimeout(function () {
memberTarget.roles.remove(muteRole.id);
memberTarget.roles.add(`791144820810842163` , `794825576602533898` , `791144908240060426` , `791144966474563624` , `791145298072305685` , `791145926344966185` , `791146191336505414` , `791146355552682034` , `792565793568587796` , `795357387794939904` , `795358283623432213` , `798804993468530699` , `791146747367653387`);
}, ms(args[1]));
} else{
message.channel.send('Cant find that member!');
}let cachedUserRoles = {};
}
}
答案 0 :(得分:1)
message.guild.roles.cache.get
、memberTarget.roles.remove
和 memberTarget.roles.add
不支持多个参数。您需要先将角色添加到列表中,然后对其进行迭代。
const mainRoles = [`791144820810842163` , `794825576602533898` , `791144908240060426` , `791144966474563624` , `791145298072305685` , `791145926344966185` , `791146191336505414` , `791146355552682034` , `792565793568587796` , `795357387794939904` , `795358283623432213` , `798804993468530699` , `791146747367653387`];
module.exports = {
name: `jail`,
description: "this is jail command!",
execute(message, args){
const member = message.mentions.users.first();
if(member){
const memberTarget = message.guild.members.cache.get(member.id);{
if (!message.member.hasPermission("MANAGE_MESSAGES")) return message.channel.send("You cant jail person because you are not staff/co owner/owner");
}
let muteRole = message.guild.roles.cache.find(role => role.name === 'Jailed');
if (!args[1]) {
mainRoles.forEach(roleId => memberTarget.roles.remove(roleId));
memberTarget.roles.add(muteRole.id);
message.channel.send(`<@${memberTarget.user.id}> has been Jailed`);
return
}
mainRoles.forEach(roleId => memberTarget.roles.remove(roleId));
memberTarget.roles.add(muteRole.id);
message.channel.send(`<@${memberTarget.user.id}> has been Jailed for ${(ms(args[1]))}`);
setTimeout(function () {
memberTarget.roles.remove(muteRole.id);
mainRoles.forEach(roleId => memberTarget.roles.add(roleId));
}, ms(args[1]));
} else{
message.channel.send('Cant find that member!');
}let cachedUserRoles = {};
}
}