Discord.py create_custom_emojis用法

时间:2017-04-23 16:05:39

标签: python discord

我正在使用Discord.py创建一个机器人,我有一些问题如何使用函数create_custom_emojis(),因为无论我做什么,我都会收到HTTP错误400.

这是我创建表情符号的代码:

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)

我得到的错误:

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)

2 个答案:

答案 0 :(得分:0)

image_byte = image.read()

请勿尝试从图像中读取。它已经是像对象一样的字节。只需将其作为图像发送。

emoji = await self.bot.create_custom_emoji(server, name="emo", image=image)

答案 1 :(得分:0)

我不完全确定确切的代码,但你可以使用get_all_emojis()函数 - 在Discord API中阅读它。