Why client.emojis, newer version of client.get_all_emojis() returns empy list when using Discord's Python API?

会有一股神秘感。 提交于 2020-07-09 14:31:47

问题


Based on this, this, this & this, I expected client.get_all_emojis() to work in my Discord chat bot:

import discord
from dotenv import load_dotenv
import asyncio
import os

load_dotenv()
TOKEN = os.getenv('DISCORD_TOKEN')
GUILD = os.getenv('DISCORD_GUILD')

client = discord.Client()

@client.event
async def on_message(message):
    if message.content == 'send emoji':
        await message.channel.send(client.get_all_emojis()[0])

client.run(TOKEN)

I expected client.get_all_emojis() to be a list, & wanted the bot to send the first element of that list. I get however:

Traceback (most recent call last):
File "/home/ps738/.local/lib/python3.8/site-packages/discord/client.py", line 312, in _run_event

await coro(*args, **kwargs) > File "bot5.py", line 15, in on_message

await message.channel.send(client.get_all_emojis()[0]) > AttributeError: 'Client' object has no attribute 'get_all_emojis'

Main point: 'Client' object has no attribute 'get_all_emojis'.

How can I fix this?


ADD

Based on Patrick's comment to this answer & this source of PrimeEpoch's answer to my question, I tried replacing client.get_all_emojis()[0] with client.emojis[0]. Now it says: IndexError: list index out of range, so probably an empty list was returned, which is not ideal.


回答1:


It may be because you're using the rewrite version of discord.py, from what I found here, you should use client.emojis



来源:https://stackoverflow.com/questions/62544309/why-client-emojis-newer-version-of-client-get-all-emojis-returns-empy-list-wh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!