'Adding a custom Emoji (Discord.py)
Code:
...
@client.event
async def on_message(message):
if 'e_lastprism' in message.content.lower():
await message.delete()
await message.guild.create_custom_emoji(name = ('lastprism'), image = (b'D:\Desktop\diskord BOT\emoji\lastprism.jpg'))
...
After entering, an error emerges:
discord.errors.InvalidArgument: Unsupported image type given
Full Error:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Program Files\Python37\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "bot.py", line 251, in on_message
await message.guild.create_custom_emoji(name = ("lastprism"), image = (b'D:\Desktop\diskord BOT\emoji\lastprism.jpg'))
File "C:\Program Files\Python37\lib\site-packages\discord\guild.py", line 1504, in create_custom_emoji
img = utils._bytes_to_base64_data(image)
File "C:\Program Files\Python37\lib\site-packages\discord\utils.py", line 299, in _bytes_to_base64_data
mime = _get_mime_type_for_image(data)
File "C:\Program Files\Python37\lib\site-packages\discord\utils.py", line 295, in _get_mime_type_for_image
raise InvalidArgument('Unsupported image type given')
discord.errors.InvalidArgument: Unsupported image type given
How can I fix this?
Solution 1:[1]
I have not came across this one before but try using .jpg or .jpeg. as it says the wrong image type.
Solution 2:[2]
I fix my code with:
with open("D:\Desktop\diskord BOT\emoji\lastprism.png", "rb") as img:
img_byte = img.read()
await message.guild.create_custom_emoji(name = ("lastprism"), image = img_byte)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | DrNano |
| Solution 2 | Lev145 |
