I am coding a discord.js bot and need a command where the first argument is a Message-ID.
Because a fetch()
returns a promise, it's not guaranteed that the message will be found (obviously if the ID is wrong), so only if finds the message, it goes into the .then()
, if not, I just make .catch(msg.delete())
BUT, I still get a warning in the console UnhandledPromiseRejectionWarning: DiscordAPIError: Unknown Message
But if I change the catch block to .catch(console.error)
the warnings vanish and I get a object-kinda output. But I dont that this error will be displayed in my console, neither I want those warnings. My bot should just remove the message, because it's the users fault to type an invalid id.
And one question: when exactly does the catch block trigger, if the ID (args[0]) is per se valid (18 chars and only numbers) but still not matching to any message, or if its just anything causing an error in the Promise.
Thanks in advance!
Here is a bit more code:
msg.channel.messages.fetch(args[0])
.then(message => {
console.log("then");
})
.catch(console.log("catch"));
what's really interesting, if my ID is valid, then it says first "catch", and then "then". If its invalid it says "catch" and then comes the warning message