mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-08 04:38:42 +00:00
Add event system based on a public dispatch method in Client. The new event system bases itself on two types of events, internal event handlers and user defined event handlers. Internal event handlers begin with 'handle_', and user defined events begin with 'on_'. Events are dispatched with dispatch(event_name, *args). The Client class should be subclassed and the on_<event> handlers defined in it for responding to events. The handle_<event> handlers can the overridden to override the behaviour of the Client class, though this is not recommended. The subclassing method allows separation of the instance of the client and the code that handles it. (i.e. you don't need the instance of the client object to define event handlers for it). Though, the old method of using the event decorator from the instance will still be supported.
discord.py
discord.py is an API wrapper for Discord written in Python.
This was written to allow easier writing of bots or chat logs.
Installing
Installing is pretty easy.
pip install discord.py
Will install the latest 'stable' version of the library.
This module is alpha!
The discord API is constantly changing and the wrapper API is as well. There will be no effort to keep backwards compatibility.
I recommend that you follow the discussion in the unofficial Discord API discord channel and update your installation periodically through pip install --upgrade discord.py
.
Quick Example
import discord
client = discord.Client()
client.login('email', 'password')
@client.event
def on_message(message):
if message.content.startswith('!hello'):
client.send_message(message.channel, 'Hello was received!')
@client.event
def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
client.run()
You can find examples in the examples directory.
Requirements
- Python 2.7+ or Python 3.3+.
ws4py
libraryrequests
library
Usually pip
will handle these for you.
Related Projects
Languages
Python
100%