Rapptz / discord.py

An API wrapper for Discord written in Python.
http://discordpy.rtfd.org/en/latest
MIT License
14.9k stars 3.77k forks source link

add_reaction with string throwing discord.errors.HTTPException: 400 #9116

Closed NatasFX closed 1 year ago

NatasFX commented 1 year ago

Summary

add_reaction('<:thisisemoji:0123456789>') gives 400 http error code

Reproduction Steps

I'm on discord.py 1.7.3, and suddently today my bot started giving discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body In emoji_id: Value "sce" is not snowflake. when trying to add a reaction to a message using a string of the custom guild emoji id, like this: message.add_reaction('<:customguildemoji:012345678901010010>')

full traceback:

Traceback (most recent call last):
  File "/home/natas/.local/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "/home/natas/study/botCogs/minigrupo.py", line 58, in minigrupo
    await self.editaFicha(ctx, author)
  File "/home/natas/study/botCogs/minigrupo.py", line 142, in editaFicha
    await msg.add_reaction('<:sce:928698582415056996>')
  File "/home/natas/.local/lib/python3.8/site-packages/discord/message.py", line 1223, in add_reaction
    await self._state.http.add_reaction(self.channel.id, self.id, emoji)
  File "/home/natas/.local/lib/python3.8/site-packages/discord/http.py", line 254, in request
    raise HTTPException(r, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In emoji_id: Value "sce" is not snowflake.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/natas/.local/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
    await ctx.command.invoke(ctx)
  File "/home/natas/.local/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "/home/natas/.local/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In emoji_id: Value "sce" is not snowflake.

Minimal Reproducible Code

No response

Expected Results

Emoji correcltly added to the message.

Actual Results

HTTP error 400.

Intents

all intents.

System Information

Checklist

Additional Context

No response

NatasFX commented 1 year ago

Update: remove_reaction also shows the same behavior. Getting the emoji with client.get_emoji(EMOJI_ID) where emoji_id is the number part in the string above works, thus message.add_reaction(client.get_emoji(EMOJI_ID)) works fine.

Robin5605 commented 1 year ago

Link to discussion in the "Discord Developers" server

Stripping the leading : seems to do the trick:

https://github.com/Rapptz/discord.py/blob/799e3c5bf09cedcd9b7e2b83df733910fa11532a/discord/message.py#L125

Could be changed to return emoji.strip('<:>')

Robin5605 commented 1 year ago

Seems to be a breaking API change, and has broken our bot at Python Discord. However I'm not 100% sure because I don't see any mention of it in changelogs or the official discord API reference

NatasFX commented 1 year ago

Link to discussion in the "Discord Developers" server

Stripping the leading : seems to do the trick:

  • <:Arch:905328118078775296> does not work
  • <Arch:905328118078775296> works as expected (this is a custom emoji from my server. the actual emoji doesn't matter)

https://github.com/Rapptz/discord.py/blob/799e3c5bf09cedcd9b7e2b83df733910fa11532a/discord/message.py#L125

Could be changed to return emoji.strip('<:>')

Can confirm, it indeed works.

Robin5605 commented 1 year ago

Can confirm, it indeed works.

Did you try monkeypatching it in the discord.py internals?

NatasFX commented 1 year ago

Can confirm, it indeed works.

Did you try monkeypatching it in the discord.py internals?

I had tried just removing the first :, altering the message.py as you said also worked.

Robin5605 commented 1 year ago

Great. Looks like it should be a simple internal fix, then.

Robin5605 commented 1 year ago

This was fixed on Discord's side. Issue can be closed.