claabs/markov-discord

Bot crash error when the message is instantly deleted

Closed this issue · 1 comments

I have auto-moderation running on my server, which deletes bad messages, and it turns out that when the bot is pinged and auto-moderation instantly deletes the message with ping, an error is caused and the bot crashes

[2022-04-14 20:23:54.678 +0000] INFO: Generated response text
    string: "Эй котик где твой \"господин\"? Просто я его"

/usr/app/node_modules/discord.js/src/rest/RequestHandler.js:350
      throw new DiscordAPIError(data, res.status, request);
            ^
DiscordAPIError: Invalid Form Body
message_reference: Unknown message
    at RequestHandler.execute (/usr/app/node_modules/discord.js/src/rest/RequestHandler.js:350:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at RequestHandler.push (/usr/app/node_modules/discord.js/src/rest/RequestHandler.js:51:14)
    at TextChannel.send (/usr/app/node_modules/discord.js/src/structures/interfaces/TextBasedChannel.js:175:15)
    at handleResponseMessage (/usr/app/src/index.ts:612:34)
    at Client.<anonymous> (/usr/app/src/index.ts:699:9)

Makes sense. message.reply is used, so if the ping message doesn't exist, it errors. Looks like I should set failIfNotExists: false.