Mentioning an out-of-server user gives a crash in revolt.websocket.handle_message #27

Closed
opened 2026-02-15 23:16:17 -05:00 by yindo · 0 comments
Owner

Originally created by @MysticMia on GitHub (Jul 2, 2023).

Describe the bug
If a member mentions a user that isn't in cache (the crash happens in DMs too, apparently), it crashes. This is especially an issue if the bot sends a message mentioning a user that isn't in the cache, specifically an out-of-serverm user, because then this crash causes the current function to stop.

To Reproduce

@commands.command()
async def ban(ctx, member_id):
    # assuming the given member_id is a member that isn't in the bot's cache- not being in any of the user's servers.
    # <@01234567890123456789012345> works/crashes too
    print("First print statement")
    await ctx.send(f"<\@{ctx.author.id}> _banned_ <@{member_id}>")
    print("Second print statement")

Expected behavior
I expected to see "Second print statement" being printed in console, but this didn't happen due to it crashing.

Traceback

Traceback (most recent call last):
  File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\ext\commands\command.py", line 80, in invoke
    return await self.callback(self.cog or context.client, context, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mia\Documents\GitHub\uncute-rina-revolt\cmd_moderation.py", line 43, in ban
    await log_channel.send(f":hammer: <\@{ctx.author.id}> _banned_ out-of-server user [`{member_id}`, <@{member_id}>]" +
  File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\messageable.py", line 68, in send
    return self.state.add_message(message)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\state.py", line 92, in add_message
    message = Message(payload, self)
              ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\message.py", line 88, in __init__
    self.mentions = [self.server.get_member(member_id) for member_id in data.get("mentions", [])]
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\message.py", line 88, in <listcomp>
    self.mentions = [self.server.get_member(member_id) for member_id in data.get("mentions", [])]
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\server.py", line 243, in get_member
    raise LookupError from None
LookupError

Task exception was never retrieved
future: <Task finished name='Task-40' coro=<WebsocketHandler.handle_event() done, defined at C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\websocket.py:103> exception=LookupError()>
Traceback (most recent call last):
  File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\websocket.py", line 115, in handle_event
    await func(payload)
  File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\websocket.py", line 152, in handle_message
    message = self.state.add_message(cast(MessagePayload, payload))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\state.py", line 92, in add_message
    message = Message(payload, self)
              ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\message.py", line 88, in __init__
    self.mentions = [self.server.get_member(member_id) for member_id in data.get("mentions", [])]
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\message.py", line 88, in <listcomp>
    self.mentions = [self.server.get_member(member_id) for member_id in data.get("mentions", [])]
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\server.py", line 243, in get_member
    raise LookupError from None
LookupError

Note how there are 2 crashes: 1 for my bot's function sending a message with an out-of-server member that tries to return the sent message, and one for the handle_message event that tries to add the message to cache. Both have the same error source though.

Library version
Version 0.1.11 commit 5ee3c60 (most recent GitHub version)

Additional context
The crash resulting in the discontinuation of your function can be caught by catching the LookupError, but you will still get a crash for the handle_event()

Originally created by @MysticMia on GitHub (Jul 2, 2023). **Describe the bug** If a member mentions a user that isn't in cache (the crash happens in DMs too, apparently), it crashes. This is especially an issue if the bot sends a message mentioning a user that isn't in the cache, specifically an out-of-serverm user, because then this crash causes the current function to stop. **To Reproduce** ```py @commands.command() async def ban(ctx, member_id): # assuming the given member_id is a member that isn't in the bot's cache- not being in any of the user's servers. # <@01234567890123456789012345> works/crashes too print("First print statement") await ctx.send(f"<\@{ctx.author.id}> _banned_ <@{member_id}>") print("Second print statement") ``` **Expected behavior** I expected to see "Second print statement" being printed in console, but this didn't happen due to it crashing. **Traceback** ``` Traceback (most recent call last): File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\ext\commands\command.py", line 80, in invoke return await self.callback(self.cog or context.client, context, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Mia\Documents\GitHub\uncute-rina-revolt\cmd_moderation.py", line 43, in ban await log_channel.send(f":hammer: <\@{ctx.author.id}> _banned_ out-of-server user [`{member_id}`, <@{member_id}>]" + File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\messageable.py", line 68, in send return self.state.add_message(message) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\state.py", line 92, in add_message message = Message(payload, self) ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\message.py", line 88, in __init__ self.mentions = [self.server.get_member(member_id) for member_id in data.get("mentions", [])] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\message.py", line 88, in <listcomp> self.mentions = [self.server.get_member(member_id) for member_id in data.get("mentions", [])] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\server.py", line 243, in get_member raise LookupError from None LookupError Task exception was never retrieved future: <Task finished name='Task-40' coro=<WebsocketHandler.handle_event() done, defined at C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\websocket.py:103> exception=LookupError()> Traceback (most recent call last): File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\websocket.py", line 115, in handle_event await func(payload) File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\websocket.py", line 152, in handle_message message = self.state.add_message(cast(MessagePayload, payload)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\state.py", line 92, in add_message message = Message(payload, self) ^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\message.py", line 88, in __init__ self.mentions = [self.server.get_member(member_id) for member_id in data.get("mentions", [])] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\message.py", line 88, in <listcomp> self.mentions = [self.server.get_member(member_id) for member_id in data.get("mentions", [])] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Mia\AppData\Local\Programs\Python\Lib\site-packages\revolt\server.py", line 243, in get_member raise LookupError from None LookupError ``` Note how there are 2 crashes: 1 for my bot's function sending a message with an out-of-server member that tries to return the sent message, and one for the handle_message event that tries to add the message to cache. Both have the same error source though. **Library version** Version 0.1.11 commit 5ee3c60 (most recent GitHub version) **Additional context** The crash resulting in the discontinuation of your function can be caught by catching the LookupError, but you will still get a crash for the handle_event()
yindo added the unconfirmed bug label 2026-02-15 23:16:17 -05:00
yindo closed this issue 2026-02-15 23:16:17 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: stoatchat/python-client-sdk#27