我正在尝试从一台服务器中提取表情符号并将其添加到我的服务器中。当我到达实际上用client.create_custom_emoji
添加表情符号的行时,出现错误。
错误:
AttributeError: '_io.BufferedWriter' object has no attribute 'startswith'
完整:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\bot\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 307, in _run_event
yield from getattr(self, event)(*args, **kwargs)
File "c:\Users\bot\Desktop\bottest\bot.py", line 2429, in on_message
await client.create_custom_emoji(server=message.server, name="mojihere", image=image)
File "C:\Users\bot\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\client.py", line 2515, in create_custom_emoji
img = utils._bytes_to_base64_data(image)
File "C:\Users\bot\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\utils.py", line 247, in _bytes_to_base64_data
mime = _get_mime_type_for_image(data)
File "C:\Users\bot\AppData\Local\Programs\Python\Python36\lib\site-packages\discord\utils.py", line 238, in _get_mime_type_for_image
if data.startswith(b'\x89\x50\x4E\x47\x0D\x0A\x1A\x0A'):
AttributeError: '_io.BufferedWriter' object has no attribute 'startswith'
代码:
if message.content.lower().startswith('!take'):
mojiid = re.findall(r'<a:\w*:\d*>', message.content)
mojiid = [e.split(':')[2].replace('>', '') for e in mojiid]
with requests.get("https://cdn.discordapp.com/emojis/{}.gif?v=1".format(mojiid[0])) as r:
img_data = r.content
with open('moji.gif', 'wb') as handler:
handler.write(img_data)
with open("moji.gif", 'rb') as image:
await client.create_custom_emoji(server=message.server, name="mojihere", image=image)