CodecademyCommunity / codecademy-discord-bot

Custom moderation bot for the official Codecademy Community Discord server.
https://codecademycommunity.github.io/
MIT License
11 stars 1 forks source link

Bot restarts on unhandled discord API-errors after upgrade to node 16 in upgrade-to-v13 branch #271

Closed mikejoh12 closed 2 years ago

mikejoh12 commented 2 years ago

Describe the bug

The bot restarts on unhandled discord API-errors after upgrade to node 16 in upgrade-to-v13 branch. In node v14 and our previous bot, these errors did not cause a crash and reboot of the bot. A relatively large surface of the code has promise code (using the discord.js library) that is not wrapped in try/catch blocks. This is related to how node has changed the handling of unhandled rejected promises since node v15.

Expected behavior

Server should not reboot due to discord API errors which seems like a kind of error that can to some degree be expected.

To Reproduce

Start the bot under the upgrade-to-v13 branch. Create an error in one of the commands. One way to trigger such an error is to remove the argument to the .send method in the command and then run the command.

Additional context

Discord.js guide shows similar error handling here: https://discordjs.guide/popular-topics/errors.html#how-to-diagnose-api-errors We are adding a notification of the error to a channel where they can be seen by bot developers