rHomelab / LabBot-Cogs

Cogs for the Red-based Homelab Discord server bot.
GNU General Public License v3.0
36 stars 14 forks source link

[BUG] autoreact cog doesn't handle quickly deleted messages #232

Closed tigattack closed 1 year ago

tigattack commented 1 year ago

Describe the bug

If a message is sent in a channel with autoreacts configured (e.g. #labpics in Homelab) and then very quickly deleted (e.g. in the case of a non-compliant #labpics post, quickly removed by the enforcer cog), the autoreact cog throws an exception when it can't find the message to react to.

To Reproduce Steps to reproduce the behavior:

  1. Send message in autoreact-configured channel
  2. Delete it very quickly
  3. See exception

Expected behavior

Error is caught and handled.

Screenshots

Additional context

[2023-05-16 09:26:31] [ERROR] discord.client: Ignoring exception in on_message
Traceback (most recent call last):
  File "/home/redbot/.local/lib/python3.11/site-packages/discord/client.py", line 441, in _run_event
    await coro(*args, **kwargs)
  File "/redbot/data/cogs/CogManager/cogs/autoreact/autoreact.py", line 43, in on_message
    await message.add_reaction(reaction)
  File "/home/redbot/.local/lib/python3.11/site-packages/discord/message.py", line 1098, in add_reaction
    await self._state.http.add_reaction(self.channel.id, self.id, emoji)
  File "/home/redbot/.local/lib/python3.11/site-packages/discord/http.py", line 740, in request
    raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10008): Unknown Message