Discord.py create_custom_emojis 用法

Posted

技术标签:

【中文标题】Discord.py create_custom_emojis 用法【英文标题】:Discord.py create_custom_emojis usage 【发布时间】:2017-09-20 06:29:12 【问题描述】:

我正在使用 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)

【问题讨论】:

【参考方案1】:
image_byte = image.read()

不要尝试从图像中读取。它已经是一个类似字节的对象。只需将此作为图像发送即可。

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

【讨论】:

【参考方案2】:

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

【讨论】:

以上是关于Discord.py create_custom_emojis 用法的主要内容,如果未能解决你的问题,请参考以下文章