问题
I have made a freeze command using discord.js and commando, that gives the user a role, and keeps them from talking and chatting. It seems that every time I run it though, it tosses an error:
(node:7352) UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown Message
I haven't been able to find what it is, but maybe i'm just a nub.
Code:
async run(message, { user }) {
message.delete()
const member = message.guild.member(user);
if (!message.member.hasPermission("MUTE_MEMBERS")) return message.say("Sorry, but you do not have the Mute Members Permission! If you beleive this is a error, contact an owner.");
if (!user) return message.say(`Cannot find user!`)
if (member.hasPermission("MUTE_MEMBERS")) return message.say("The user you are trying to freeze is either the same, or higher role than you.");
let muterole = message.guild.roles.find(`name`, "Frozen");
if (member.roles.has(muterole)) return message.say(`${user.username} is already frozen!`);
if (!muterole) {
try {
muterole = await message.guild.createRole({
name: "Frozen",
color: "#000000",
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);
}
await (member.addRole(muterole.id))
message.say(`**${user.username} has been frozen! To unfreeze them, use the unfreeze command!**`)
message.delete(5000)
}
}
Any help would be appreciated! Thanks.
回答1:
I think that's caused by the fact that you're deleting the message with message.delete() in the first lines, but at the end you do that again with message.delete(5000).
The rest of the code runs fine because even if you deleted the message it's still saved in your message variable, but when you try to delete that again the API isn't able to find it. Try removing one of the message.delete()
来源:https://stackoverflow.com/questions/50536834/discordapierror-unknown-message