Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support reaction type #129

Open
alkshmir opened this issue Aug 31, 2024 · 1 comment
Open

Support reaction type #129

alkshmir opened this issue Aug 31, 2024 · 1 comment

Comments

@alkshmir
Copy link

Is your feature request related to a problem? Please describe.

discord.py 2.4.0 adds the support for reaction type (Rapptz/discord.py#9836) and this breaks the existing tests including the add_reaction().
Specifically, it raises KeyError: 'type' when running test:

ERROR    discord.client:client.py:523 Ignoring exception in on_message
Traceback (most recent call last):
  File "/Users/user/work/mybot/.venv/lib/python3.12/site-packages/discord/client.py", line 449, in _run_event
    await coro(*args, **kwargs)
  File "/Users/user/work/mybot/src/cogs/songlink.py", line 54, in convert_apple_music_link
    await message.add_reaction(
  File "/Users/user/work/mybot/.venv/lib/python3.12/site-packages/discord/message.py", line 1258, in add_reaction
    await self._state.http.add_reaction(self.channel.id, self.id, emoji)
  File "/Users/user/work/mybot/.venv/lib/python3.12/site-packages/discord/ext/test/backend.py", line 243, in add_reaction
    add_reaction(message, user, emoji)
  File "/Users/user/work/mybot/.venv/lib/python3.12/site-packages/discord/ext/test/backend.py", line 983, in add_reaction
    state.parse_message_reaction_add(data)
  File "/Users/user/work/mybot/.venv/lib/python3.12/site-packages/discord/state.py", line 714, in parse_message_reaction_add
    raw = RawReactionActionEvent(data, emoji, 'REACTION_ADD')
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/user/work/mybot/.venv/lib/python3.12/site-packages/discord/raw_models.py", line 254, in __init__
    self.type: ReactionType = try_enum(ReactionType, data['type'])
                                                     ~~~~^^^^^^^^
KeyError: 'type'

Describe the solution you'd like

When I add type field in backend.py::add_reaction() the tests are successful.

    data = {
        "message_id": message.id,
        "channel_id": message.channel.id,
        "user_id": user.id,
        "emoji": emoji,
        "type": discord.enums.ReactionType.normal,  # add
    }

data = {
"message_id": message.id,
"channel_id": message.channel.id,
"user_id": user.id,
"emoji": emoji
}

Describe alternatives you've considered

I'm ready to open PR but I don't fully understand how can I add test for this issue yet.

Additional context

I'm using discord.py 2.4.0 and dpytest 0.7.0.

It seems reaction type has been added in this commit: Rapptz/discord.py@f77ba71

@Sergeileduc
Copy link
Collaborator

OK ! thanks !!

I'll try to implement this ASAP !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants