Skip to content

Crash from Automod due to missing key in data structure.  #8264

@aldalen

Description

@aldalen

Summary

Crash from automod with "content" key not found.

Reproduction Steps

I can't seem to replicate this locally since its dependent on certain discord settings, but I see it in my production bot instance.

Minimal Reproducible Code

No response

Expected Results

No crash :)

Actual Results

Traceback (most recent call last):
  File "./runtime.py", line 31, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "./runtime.py", line 27, in main
    await bot.start(os.getenv('TOKEN', os.getenv("DISCORD_API_KEY")))
  File "./.venv/lib/python3.10/site-packages/discord/client.py", line 791, in start
    await self.connect(reconnect=reconnect)
  File "./.venv/lib/python3.10/site-packages/discord/shard.py", line 461, in connect
    raise item.error
  File "./.venv/lib/python3.10/site-packages/discord/shard.py", line 163, in worker
    await self.ws.poll_event()
  File "./.venv/lib/python3.10/site-packages/discord/gateway.py", line 608, in poll_event
    await self.received_message(msg.data)
  File "./.venv/lib/python3.10/site-packages/discord/gateway.py", line 558, in received_message
    func(data)
  File "./.venv/lib/python3.10/site-packages/discord/state.py", line 1121, in parse_auto_moderation_action_execution
    execution = AutoModAction(data=data, state=self)
  File "./.venv/lib/python3.10/site-packages/discord/automod.py", line 450, in __init__
    self.content: str = data['content']
KeyError: 'content'

Intents

Intents.default()

System Information

  • Python v3.10.5-final
  • discord.py v2.0.0-alpha
    • discord.py pkg_resources: v2.0.0a4424+g31189191
  • aiohttp v3.8.1
  • system info: Linux 5.15.39-1-pve Fix issue with author changing type #1 SMP PVE 5.15.39-1 (Wed, 22 Jun 2022 17:22:00 +0200)

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

I don't need automod in my bot, so to get around the issue I just changed the offending line to:
self.content: str = data['content'] if "content" in data else ""

I am not sure what is the best solution here. Could change to an Optional[str] as and then just set to None if not in the data dict?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis is a bug with the library.discord bugThis is a Discord bug, not one with the library.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions