discordjs-bot-guide
discordjs-bot-guide copied to clipboard
Fixing ReferenceError in catch block
Sending error to channel results in a ReferenceError because cleaned is not defined in the catch block's scope.
Replaced with sending the error's stack to resolve this.
can you screenshot what actually happens?
message.channel.send(`\`ERROR\` \`\`\`xl\n${cleaned}\n\`\`\``);
^
ReferenceError: cleaned is not defined
As cleaned is not defined in the catch block, a ReferenceError is thrown. Error#stack lazily generates a string, which to the best of my knowledge should always be populated once accessed.
You could always just send the plain Error, but that will not provide any information regarding the actual location of the error, just the type and message associated with it.