我最近一直在思考这段代码,时间最长。我可以添加角色,但是第二次尝试删除角色时,没有错误,也没有实际删除其角色。
我曾尝试在互联网上查找此问题,但每个问题都不相同,或者没有解决。我还尝试完全复制我的添加角色命令,只是将“ addRole
”更改为“ removeRole
”,但这仍然行不通。
// Unmute.js
/* ... */
exports.run = async(client,message,args) => {
/* ... */
let mutee = message.mentions.members.first() || message.guild.members.get(args[0])
if (!mutee) return message.channel.send("You did not mention a user!")
let reason = args.slice(1).join(" ")
if (!reason) reason = "No reason."
let muterole = message.guild.roles.find(r => r.property === "Muted")
if (!muterole) {
try {
muterole = await message.guild.createRole({
name: "Muted",
color: "#514f48",
permissions: []
})
message.guild.channels.forEach(async(channel, id) => {
await channel.overwritePermissions(muterole, {
SEND_MESSAGES: false,
ADD_REACTIONS: false,
SPEAK: false
});
})
} catch(e) {
console.log(e.stack)
}
}
/* ... */
mutee.removeRole(muterole.id).then(() => {
message.delete()
/* ... */
});
}
// Mute.js
/* ... */
exports.run = async(client,message,args) => {
/* ... */
let mutee = message.mentions.members.first() || message.guild.members.get(args[0])
if (!mutee) return message.channel.send("You did not mention a user!")
let reason = args.slice(1).join(" ")
if (!reason) reason = "No reason."
let muterole = message.guild.roles.find(r => r.property === "Muted")
if (!muterole) {
try {
muterole = await message.guild.createRole({
name: "Muted",
color: "#514f48",
permissions: []
})
message.guild.channels.forEach(async(channel, id) => {
await channel.overwritePermissions(muterole, {
SEND_MESSAGES: false,
ADD_REACTIONS: false,
SPEAK: false
});
})
} catch(e) {
console.log(e.stack)
}
}
/* ... */
mutee.addRole(muterole.id).then(() => {
message.delete()
/* ... */
});
}
(除非有必要,否则所有不必要的部分都会被切除)
运行%mute [user]
时,我期望的结果是使用户静音,而这样做的结果是。我对%unmute [user]
期望的结果当然是取消静音用户,它不会取消静音用户,而是继续执行“ then”语句,该语句仅在取消静音用户成功后才运行。没有任何错误打印或任何错误,因此我一点也不理解该问题。