This is a list of Frequently Asked Questions regarding using discord.py
and its extension modules. Feel free to suggest anew question or submit one via pull requests.
Questions
For example, pressing alt and 128110 keys will produce the police officer emoji like đŽ. Examples of Emoji. Below are some of the examples, you can use emoji symbols in Outlook or Skype chat. Instead of typing a long sentence, a single emoji can express your thoughts more clearly. Oct 05, 2020 The emoji could be used to depict both â a flying punch and a bro-fist â depending on who youâre speaking with. Fists Facing Left and Right. These emoji can be best used together to represent fist bumps or to show resistance or agitation towards an object with the help of other emoji. Raised Backhand. Emoji with skin-tones are not listed here: see Full Skin Tone List. For counts of emoji, see Emoji Counts. While these charts use a particular version of the Unicode Emoji data files, the images and format may be updated at any time. For any production usage, consult those data files.
How to use emoji dictionary. This page lists all smiley meanings with pictures. If you know emoji name and want to find corresponding emoji picture with this Emoji Dictionary, enter one or more keywords into the search field in the menu, and you will immediately get all relevant emoji list with their meanings.
Questions regarding coroutines and asyncio belong here.
A coroutine is a function that must be invoked with await
or yieldfrom
. When Python encounters an await
it stopsthe functionâs execution at that point and works on other things until it comes back to that point and finishes off its work.This allows for your program to be doing multiple things at the same time without using threads or complicatedmultiprocessing.
Giggs When Will It Stop Zip It Emoji Copy
If you forget to await a coroutine then the coroutine will not run. Never forget to await a coroutine.
You can only use await
inside asyncdef
functions and nowhere else.
In asynchronous programming a blocking call is essentially all the parts of the function that are not await
. Do notdespair however, because not all forms of blocking are bad! Using blocking calls is inevitable, but you must work to makesure that you donât excessively block functions. Remember, if you block for too long then your bot will freeze since it hasnot stopped the functionâs execution at that point to do other things.
If logging is enabled, this library will attempt to warn you that blocking is occurring with the message:HeartbeatblockedformorethanNseconds.
See Setting Up Logging for details on enabling logging.
A common source of blocking for too long is something like time.sleep()
. Donât do that. Use asyncio.sleep()
instead. Similar to this example:
Another common source of blocking for too long is using HTTP requests with the famous module requests.While requests is an amazing module for non-asynchronous programming, it is not a good choice forasyncio
because certain requests can block the event loop too long. Instead, use the aiohttp library whichis installed on the side with this library.
Consider the following example:
General questions regarding library usage belong here.
Example code can be found in the examples folderin the repository.
There is a method for this under Client
called Client.change_presence()
.The relevant aspect of this is its activity
keyword argument which takes in an Activity
object.
The status type (playing, listening, streaming, watching) can be set using the ActivityType
enum.For memory optimisation purposes, some activities are offered in slimmed down versions:
Putting both of these pieces of info together, you get the following:
You must fetch the channel directly and then call the appropriate method. Example:
Get the User
or Member
object and call abc.Messageable.send()
. For example:
If you are responding to an event, such as on_message()
, you already have the User
object via Message.author
:
abc.Messageable.send()
returns the Message
that was sent.The ID of a message can be accessed via Message.id
:
To upload something to Discord you have to use the File
object.
A File
accepts two parameters, the file-like object (or file path) and the filenameto pass to Discord when uploading.
If you want to upload an image itâs as simple as:
If you have a file-like object you can do as follows:
To upload multiple files, you can use the files
keyword argument instead of file
:
If you want to upload something from a URL, you will have to use an HTTP request using aiohttpand then pass an io.BytesIO
instance to File
like so:
You use the Message.add_reaction()
method.
If you want to use unicode emoji, you must pass a valid unicode code point in a string. In your code, you can write this in a few different ways:
'đ'
'U0001F44D'
'N{THUMBSUPSIGN}'
Quick example:
In case you want to use emoji that come from a message, you already get their code points in the content without needingto do anything special. You cannot send ':thumbsup:'
style shorthands.
For custom emoji, you should pass an instance of Emoji
. You can also pass a '<:name:id>'
string, but if youcan use said emoji, you should be able to use Client.get_emoji()
to get an emoji via ID or use utils.find()
/utils.get()
on Client.emojis
or Guild.emojis
collections.
The name and ID of a custom emoji can be found with the client by prefixing :custom_emoji:
with a backslash.For example, sending the message :python3:
with the client will result in <:python3:232720527448342530>
.
Quick example:
The libraryâs music player launches on a separate thread, ergo it does not execute inside a coroutine.This does not mean that it is not possible to call a coroutine in the after
parameter. To do so you must pass a callablethat wraps up a couple of aspects.
The first gotcha that you must be aware of is that calling a coroutine is not a thread-safe operation. Since we aretechnically in another thread, we must take caution in calling thread-safe operations so things do not bug out. Luckily forus, asyncio
comes with a asyncio.run_coroutine_threadsafe()
function that allows us to calla coroutine from another thread.
However, this function returns a concurrent.Future
and to actually call it we have to fetch its result. Putting all ofthis together we can do the following:
There are multiple ways of doing this. If you have a specific modelâs ID then you can useone of the following functions:
The following use an HTTP request:
If the functions above do not help you, then use of utils.find()
or utils.get()
would serve some use in findingspecific models.
Quick example:
Giggs When Will It Stop Zip It Emoji Face
To make a request, you should use a non-blocking library.This library already uses and requires a 3rd party library for making requests, aiohttp
.
Quick example:
See aiohttpâs full documentation for more information.
Discord special-cases uploading an image attachment and using it within an embed so that it will notdisplay separately, but instead in the embedâs thumbnail, image, footer or author icon.
To do so, upload the image normally with abc.Messageable.send()
,and set the embedâs image URL to attachment://image.png
,where image.png
is the filename of the image you will send.
Quick example:
Note
Due to a Discord limitation, filenames may not include underscores.
Since Discord does not dispatch this information in the gateway, the library cannot provide this information.This is currently a Discord limitation.
Questions regarding discord.ext.commands
belong here.
Overriding the default provided on_message
forbids any extra commands from running. To fix this, add abot.process_commands(message)
line at the end of your on_message
. For example:
Alternatively, you can place your on_message
logic into a listener. In this setup, you should notmanually call bot.process_commands()
. This also allows you to do multiple things asynchronously in responseto a message. Example:
In a simple command defined as:
Calling it via ?echoabc
will only fetch the first argument and disregard the rest. To fix this you should either callit via ?echo'abc'
or change the signature to have âconsume restâ behaviour. Example:
This will allow you to use ?echoabc
without needing the quotes.
The Context
contains an attribute, message
to get the originalmessage.
Example:
Use the group
decorator. This will transform the callback into a Group
which will allow you to add commands intothe group operating as âsubcommandsâ. These groups can be arbitrarily nested as well.
Example:
This could then be used as ?gitpushoriginmaster
.
Choose your emoji
- Objects
- Faces
- People
- Animals
- Food
- Travel & Places
- Transport
- Plants
- Activities
- Music