Message fails to construct when sent from a group channel #6

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

Originally created by @DivyamChadha on GitHub (Oct 29, 2021).

Describe the bug
__init__ of class Message fails when the message is sent from a group channel. The message attempts to get the server from the state but since the group channel does not belong to a server it fails with a KeyError.

To Reproduce

import asyncio
import aiohttp
import revolt

class Client(revolt.Client):

    async def on_message(self, message: revolt.Message):
        ...

async def main():
    async with aiohttp.ClientSession() as session:
        client = Client(session, "token")
        await client.start()

asyncio.run(main())

Traceback

Task exception was never retrieved
future: <Task finished name='Task-15' coro=<WebsocketHandler.handle_event() done, defined at /Users/divyamchadha/Documents/Projects/Revolt/revolt/websocket.py:70> exception=KeyError('')>
Traceback (most recent call last):
  File "/Users/divyamchadha/Documents/Projects/Revolt/revolt/websocket.py", line 79, in handle_event
    await func(payload)
  File "/Users/divyamchadha/Documents/Projects/Revolt/revolt/websocket.py", line 103, in handle_message
    message = self.state.add_message(cast(MessagePayload, payload))
  File "/Users/divyamchadha/Documents/Projects/Revolt/revolt/state.py", line 73, in add_message
    message = Message(payload, self)
  File "/Users/divyamchadha/Documents/Projects/Revolt/revolt/message.py", line 59, in __init__
    self.server = self.channel and self.channel.server
  File "/Users/divyamchadha/Documents/Projects/Revolt/revolt/channel.py", line 46, in server
    return self.state.get_server(self.server_id)
  File "/Users/divyamchadha/Documents/Projects/Revolt/revolt/state.py", line 48, in get_server
    return self.servers[id]
KeyError: ''

Library version
Commit 77fa908ad5

Originally created by @DivyamChadha on GitHub (Oct 29, 2021). **Describe the bug** `__init__` of class `Message` fails when the message is sent from a group channel. The message attempts to get the server from the state but since the group channel does not belong to a server it fails with a `KeyError`. **To Reproduce** ```py import asyncio import aiohttp import revolt class Client(revolt.Client): async def on_message(self, message: revolt.Message): ... async def main(): async with aiohttp.ClientSession() as session: client = Client(session, "token") await client.start() asyncio.run(main()) ``` **Traceback** ``` Task exception was never retrieved future: <Task finished name='Task-15' coro=<WebsocketHandler.handle_event() done, defined at /Users/divyamchadha/Documents/Projects/Revolt/revolt/websocket.py:70> exception=KeyError('')> Traceback (most recent call last): File "/Users/divyamchadha/Documents/Projects/Revolt/revolt/websocket.py", line 79, in handle_event await func(payload) File "/Users/divyamchadha/Documents/Projects/Revolt/revolt/websocket.py", line 103, in handle_message message = self.state.add_message(cast(MessagePayload, payload)) File "/Users/divyamchadha/Documents/Projects/Revolt/revolt/state.py", line 73, in add_message message = Message(payload, self) File "/Users/divyamchadha/Documents/Projects/Revolt/revolt/message.py", line 59, in __init__ self.server = self.channel and self.channel.server File "/Users/divyamchadha/Documents/Projects/Revolt/revolt/channel.py", line 46, in server return self.state.get_server(self.server_id) File "/Users/divyamchadha/Documents/Projects/Revolt/revolt/state.py", line 48, in get_server return self.servers[id] KeyError: '' ``` **Library version** Commit 77fa908ad535afc301fe84ca257c9857c79d07e5
yindo added the unconfirmed bug label 2026-02-15 23:16:11 -05:00
yindo closed this issue 2026-02-15 23:16:11 -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#6