chalda/DiscordBot

Crash due to trying to send a message to someone we cannot

Einarin opened this issue · 8 comments

treating ?help from 680686691937288234 as command
DiscordAPIError: Cannot send messages to this user
    at RequestHandler.execute (D:\Projects\DiscordBotWindows\node_modules\discord.js\src\rest\RequestHandler.js:170:25)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:94:5) {
  name: 'DiscordAPIError',
  message: 'Cannot send messages to this user',
  method: 'post',
  path: '/channels/781412747908218900/messages',
  code: 50007,
  httpStatus: 403
}

maybe a try catch to see if the message can be sent to their DM if not send a message in the channel the message was sent from to let the user know that they need to allow DM on the server for the bot to message them.

I agree with @F9Alejandro, I can do it if you want.

Well, you can just disable the exit on error, which is a bad idea imo, have it check if it can dm, then dm otherwise return

Discord js api does not let you check if you can or not send the message. The only way to know is actually sending it. so what you gotta do is catch every time you wanna send a dm so bot won't crash

I can do a quick fix and make a pull request for testing.

Edit: made changes. it is not a complete catch all as it would require its own special function for just sending the message out.
Note that doing this will require going through all the past plugins that us DM messages to use this function. Might be better than going through and adding a try catch error message for both console and channel the command was sent from for each instance.
Ex. tryDM(msg.author, Message[]); could be a function (Not actually implemented just speculation)

Dunno what you are talking about. You may want to go on github site to view the actually issue ticket