bobloy / Fox-V3

Cogs for Red-DiscordBot V3 by Bobloy
https://discord.gg/GET4DVk
GNU Affero General Public License v3.0
54 stars 91 forks source link

Timerole (seemingly) errors when a member leaves before the operation finishes #77

Closed chloecormier closed 4 years ago

chloecormier commented 4 years ago

Hey! I'm using timerole on a fairly large (50,000+ member) server, and as such, it takes a while to finish. I've noticed that occasionally it seems to error out before it finishes.

My best guess is that it's a result of someone leaving in the middle of the process in such a way that it expects them to be there when they aren't. Here's the traceback from an instance when it errored about 30 minutes after executing runtimerole:

Exception in command 'runtimerole'
Traceback (most recent call last):
  File "/home/red/.local/lib/python3.8/site-packages/discord/ext/commands/core.py", line 83, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/red/.local/share/Red-DiscordBot/cogs/CogManager/cogs/timerole/timerole.py", line 39, in runtimerole
    await self.timerole_update()
  File "/home/red/.local/share/Red-DiscordBot/cogs/CogManager/cogs/timerole/timerole.py", line 161, in timerole_update
    await self.announce_roles(title, addlist, channel, guild, to_add=True)
  File "/home/red/.local/share/Red-DiscordBot/cogs/CogManager/cogs/timerole/timerole.py", line 171, in announce_roles
    await member.add_roles(role, reason="Timerole")
  File "/home/red/.local/lib/python3.8/site-packages/discord/member.py", line 641, in add_roles
    await req(guild_id, user_id, role.id, reason=reason)
  File "/home/red/.local/lib/python3.8/site-packages/discord/http.py", line 218, in request
    raise NotFound(r, data)
discord.errors.NotFound: 404 NOT FOUND (error code: 10007): Unknown Member

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/red/.local/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 892, in invoke
    await ctx.command.invoke(ctx)
  File "/home/red/.local/lib/python3.8/site-packages/discord/ext/commands/core.py", line 797, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/home/red/.local/lib/python3.8/site-packages/discord/ext/commands/core.py", line 92, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: NotFound: 404 NOT FOUND (error code: 10007): Unknown Member
bobloy commented 4 years ago

Fixed with 9ddb1696acd0eb792daaf490a1c42aace83dbaf6