Skip to content

KeyError: 'body' in mcommand_handler.py #23

@vranki

Description

@vranki

My bot crashed with this stack trace:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/matrix_client/client.py", line 473, in listen_forever
    self._sync(timeout_ms)
  File "/usr/local/lib/python3.7/site-packages/matrix_client/client.py", line 585, in _sync
    room._put_event(event)
  File "/usr/local/lib/python3.7/site-packages/matrix_client/room.py", line 308, in _put_event
    listener['callback'](self, event)
  File "/bot/matrix_bot_api/matrix_bot_api.py", line 58, in handle_message
    if handler.test_callback(room, event):
  File "/bot/matrix_bot_api/mcommand_handler.py", line 23, in test_command
    if re.match(self.cmd_char + self.command, event['content']['body']):
KeyError: 'body'

I'm not sure what the situation is when a m.room.message does not have a body. Maybe related to some new feature such as edits or aggregations?

I suppose a check is needed if the message has body to avoid this exception.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions