gpt4 book ai didi

javascript - Bot 未在 overwritePermissions 上设置权限

转载 作者:行者123 更新时间:2023-11-30 19:46:16 25 4
gpt4 key购买 nike

我在我的 discord 机器人上有一个静音命令,当给定用户名时,给他们 Angular 色 Muted。它创建了这个 Angular 色,但我遇到的问题是它不会更改 Angular 色内的权限。我的机器人拥有执行此类操作的所有必要权限。这是我正在使用的代码:

  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}.`)
})

最佳答案

我将您的 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}.`)
})

关于javascript - Bot 未在 overwritePermissions 上设置权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54915020/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com