Introduction
This is the documentation for discord.py-message-components, a library for Python to aid in creating applications that utilise the Discord API.
Prerequisites
discord.py-message-components works with Python 3.5.3 or higher. Support for earlier versions of Python is not provided. Python 2.7 or lower is not supported. Python 3.4 or lower is not supported due to one of the dependencies (aiohttp) not supporting Python 3.4.
Installing
You can get the library directly from PyPI:
python3 -m pip install -U discord.py-message-components
If you are using Windows, then the following should be used instead:
py -3 -m pip install -U discord.py-message-components
To get voice support, you should use discord.py-message-components[voice]
instead of discord.py-message-components
, e.g.
python3 -m pip install -U discord.py-message-components[voice]
On Linux environments, installing voice requires getting the following dependencies:
For a Debian-based system, the following command will get these dependencies:
$ apt install libffi-dev libnacl-dev python3-dev
Remember to check your permissions!
Installing the developer version
To install the developer (alpha/beta) version from the developer-branch use:
# Linux/macOS
python3 -m pip install -U git+https://github.com/mccoderpy/discord.py-message-components.git@developer
# Windows
py -m pip install -U git+https://github.com/mccoderpy/discord.py-message-components.git@developer
Warning
Of course you need to have git installed on your device. If you need help with this take a look → here ←
Virtual Environments
Sometimes you want to keep libraries from polluting system installs or use a different version of libraries than the ones installed on the system. You might also not have permissions to install libraries system-wide. For this purpose, the standard library as of Python 3.3 comes with a concept called “Virtual Environment”s to help maintain these separate versions.
A more in-depth tutorial is found on Virtual Environments and Packages.
However, for the quick and dirty:
Go to your project’s working directory:
$ cd your-bot-source $ python3 -m venv bot-env
Activate the virtual environment:
$ source bot-env/bin/activate
On Windows you activate it with:
$ bot-env\Scripts\activate.bat
Use pip like usual:
$ pip install -U discord.py-message-components
Congratulations. You now have a virtual environment all set up.
Basic Concepts
discord.py-message-components revolves around the concept of events. An event is something you listen to and then respond to. For example, when a message happens, you will receive an event about it that you can respond to.
A quick example to showcase how events work:
import discord
class MyClient(discord.Client):
async def on_ready(self):
print('Logged on as {0}!'.format(self.user))
async def on_message(self, message):
print('Message from {0.author}: {0.content}'.format(message))
client = MyClient()
client.run('my token goes here')