svthalia / discord-bot

Thalia's Dicord management bot
Other
3 stars 1 forks source link

Full sync crashes when people leave the Discord #51

Closed se-bastiaan closed 3 years ago

se-bastiaan commented 3 years ago

Describe the bug

Full sync crashes when people leave the Discord

How to reproduce

Steps to reproduce the behaviour:

  1. Enter a server with your account
  2. Connect your account
  3. Now leave the server
  4. Run full sync
  5. Error

Expected behaviour

No crashes and the member is removed from DDB

se-bastiaan commented 3 years ago

I have temporarily patched this on production to prevent problems with some hideous code.

mark-boute commented 3 years ago

Could share the temporary code?

se-bastiaan commented 3 years ago

uh I could have, but I kinda forgot this so when we updated to the latest master that went into the shredder :')

se-bastiaan commented 3 years ago

Unhandled exception in internal background task 'auto_full_sync'.
Traceback (most recent call last):
  File "/home/deploy/.cache/pypoetry/virtualenvs/bot-tq7C0_9c-py3.8/lib64/python3.8/site-packages/discord/ext/tasks/__init__.py", line 101, in _loop
    await self.coro(*args, **kwargs)
  File "/opt/app/bot/cogs/sync.py", line 86, in auto_full_sync
    await self._full_sync()
  File "/opt/app/bot/cogs/sync.py", line 81, in _full_sync
    await sync_members(members, membergroups, guild, True)
  File "/opt/app/common/discord_helper.py", line 120, in sync_members
    discord_user = await guild.fetch_member(member["discord"])
  File "/home/deploy/.cache/pypoetry/virtualenvs/bot-tq7C0_9c-py3.8/lib64/python3.8/site-packages/discord/guild.py", line 1309, in fetch_member
    data = await self._state.http.get_member(self.id, member_id)
  File "/home/deploy/.cache/pypoetry/virtualenvs/bot-tq7C0_9c-py3.8/lib64/python3.8/site-packages/discord/http.py", line 243, in request
    raise NotFound(r, data)
discord.errors.NotFound: 404 Not Found (error code: 10007): Unknown Member```
se-bastiaan commented 3 years ago
if not discord_user:
            try:
                discord_user = await guild.fetch_member(member["discord"])
            except:
                continue