Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discord.py create_custom_emojis usage

Tags:

python

discord

I'm making a bot with Discord.py and I've some question how to use the function create_custom_emojis() because whatever I do, I keep getting the HTTP Error 400.

Here's my code to create the emoji:

with open("data/emojis/image.png", "rb") as image:
    image_byte = image.read()
    emoji = await self.bot.create_custom_emoji(server, name="emo", image=image_byte)

And the error I get:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python35\lib\asyncio\tasks.py", line 239, in _step
    result = coro.send(None)
  File "C:\Users\armel\Downloads\Discord bot\Red-DiscordBot\cogs\moga.py", line 385, in read_feeds
    message = await self._feed_check(server, chan_id, name, infos)
  File "C:\Users\armel\Downloads\Discord bot\Red-DiscordBot\cogs\moga.py", line 198, in _feed_check
    await self.create_custom_emojis(server)
  File "C:\Users\armel\Downloads\Discord bot\Red-DiscordBot\cogs\moga.py", line 189, in create_custom_emojis
    emoji = await self.bot.create_custom_emoji(server, name=name, image=image_byte)
  File "lib\discord\client.py", line 2519, in create_custom_emoji
    data = yield from self.http.create_custom_emoji(server.id, name, img)
  File "lib\discord\http.py", line 202, in request
    raise HTTPException(r, data)
discord.errors.HTTPException: BAD REQUEST (status code: 400)
like image 875
Bablup Avatar asked Oct 30 '22 08:10

Bablup


1 Answers

image_byte = image.read()

Do not attempt to read from image. It is already a byte like object. Simply send this as the image.

emoji = await self.bot.create_custom_emoji(server, name="emo", image=image)
like image 133
Harshith Thota Avatar answered Nov 15 '22 07:11

Harshith Thota