API Reference

The following section outlines the API of discord.py.

Client

Event Reference

This page outlines the different types of events listened to by Client.event(). All events are ‘sandboxed’, in that if an exception is thrown while the event is called then it is caught and then ignored.

discord.on_ready()

Called when the client is done preparing the data received from Discord. Usually after login is successful and the Client.servers and co. are filled up.

discord.on_message(message)

Called when a message is created and sent to a server.

Parameters:message – A Message of the current message.
discord.on_response(response)

Called whenever a message is received from the websocket. Used mainly for debugging purposes. The parameter passed is raw data that was parsed via json.loads. Note that this is called before the Client processes the event.

Parameters:response – The received message response after gone through json.loads.
discord.on_message_delete(message)
discord.on_message_edit(before, after)

Called when a message is deleted or edited from any given server. If the message is not found in the Client.messages cache, then these events will not be called. This happens if the message is too old or the client is participating in high traffic servers. To fix this, increase the max_length option of Client.

Parameters:
  • message – A Message of the deleted message.
  • before – A Message of the previous version of the message.
  • after – A Message of the current version of the message.
on_status(server, user, status, game_id):

Called whenever a user changes their status or game playing status.

The status is usually either “idle”, “online” or “offline”.

Parameters:
  • server – The Server the user belongs to.
  • user – The User whose status changed.
  • status – The new status of the user.
  • game_id – The game ID that the user is playing. Can be None.
discord.on_channel_delete(channel)

Called whenever a channel is removed from a server.

Note that you can get the server from Channel.server.

Parameters:channel – The Channel that got deleted.

Data Classes

Some classes are just there to be data containers, this lists them. It should be assumed that all classes in this category are immutable and should not be modified.