1

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.

zabop
  • 6,750
  • 3
  • 39
  • 84

1 Answers1

1

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

PrimeEpoch
  • 11
  • 2
  • 1
    Good source! The problem is that it seems to return an empty list (see ADD in OP) – zabop Jun 23 '20 at 22:13
  • @zabop Ah yeah looks like you'll need to add some emojis into your server, I believe it only works for emojis specific to your server and not the standard ones. – PrimeEpoch Jun 23 '20 at 22:45
  • Oh ok. Would you be able to show how to send the standard ones? :) – zabop Jun 23 '20 at 22:48
  • 1
    Those are just standard unicode emojis, I think you might be interested in the emoji module at https://www.geeksforgeeks.org/python-program-to-print-emojis Alternatively, you can get the specific unicode emoji you want and just paste it into your code. You can make discord send the unicode emoji by putting a backslash before sending with a regular user, so "\:joy: " will come out as , which you can copy straight into your code. – PrimeEpoch Jun 23 '20 at 23:12
  • 1
    Sorry, wrong link (oops) https://pypi.org/project/emoji/ – PrimeEpoch Jun 23 '20 at 23:20