我的discord机器人上有一个静音命令,当给其用户名时,该角色将赋予他们角色Muted
。它创建了这个角色,但是我遇到的问题是它不会更改角色中的权限。我的机器人具有执行此操作所需的所有必要权限。这是我正在使用的代码:
let tomute = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
if(!tomute) return message.reply("Usage: !mute <@user>");
if(tomute.hasPermission("MANAGE_MESSAGES")) return message.reply("Can't mute them!");
let muterole = message.guild.roles.find(`name`, "Muted");
if(!muterole){
try{
muterole = await message.guild.createRole({
name: "Muted",
color: "#000000",
permissions:[]
})
message.guild.channels.forEach(async (channel, id) => {
await channel.overwritePermissions(muterole, {
SEND_MESSAGES: false,
ADD_REACTIONS: false,
SEND_TTS_MESSAGES: false,
ATTACH_FILES: false,
SPEAK: false
});
});
}catch(e){
console.log(e.stack);
}
}
await(tomute.addRole(muterole.id));
message.reply(`<@${tomute.id}> has been muted`);
tomute.addRole(muterole.id).then(() => {
message.delete()
tomute.send(`You have been muted in ${message.guild.name}.`)
})
答案 0 :(得分:1)
我将您的forEach更改为for循环。
尝试使用以下代码:
let tomute = message.guild.member(message.mentions.users.first() || message.guild.members.get(args[0]));
if(!tomute) return message.reply("Usage: !mute <@user>");
if(tomute.hasPermission("MANAGE_MESSAGES")) return message.reply("Can't mute them!");
let muterole = message.guild.roles.find(`name`, "Muted");
if(!muterole){
try{
muterole = await message.guild.createRole({
name: "Muted",
color: "#000000",
permissions:[]
})
for (let i = 0; i < msg.guild.channels.array().length; i++) {
await msg.guild.channels.array()[i].overwritePermissions(muterole, {
SEND_MESSAGES: false,
ADD_REACTIONS: false,
SEND_TTS_MESSAGES: false,
ATTACH_FILES: false,
SPEAK: false
});
}
}catch(e){
console.log(e.stack);
}
}
await(tomute.addRole(muterole.id));
message.reply(`<@${tomute.id}> has been muted`);
tomute.addRole(muterole.id).then(() => {
message.delete()
tomute.send(`You have been muted in ${message.guild.name}.`)
})