A barebones example Discord bot, written in Python 3.6 using the discord.py library.
See also CSSBot, same idea just in C#.
This project is meant for Python 3.5 and up. Please insure that you have that
Python 3.5 or higher installed. You can check this using python --version
or python3 --version
.
Python 3.5 is shipped by default in the latest versions of Ubuntu.
You'll need to install some packages first. These are included in the
requirements.txt
file for you.
Linux:
python3 -m pip install -r requirements.txt
# only required for doing voice on Linux environments
sudo apt-get install libffi-dev python3-dev
See the discord.py documentation for why the additional tools are necessary.
Windows:
py -3 -m pip install -r requirements.txt
Mac:
python3 -m pip install -r requirements.txt
- Register your own Discord bot for testing with.
- Navigate to the Discord API docs and log in: https://discordapp.com/developers/applications/me (If you log in for the first time, it'll probably take you to the app, so go back to this link again).
- Click on the "New App" button.
- Name your app. Click "Create App".
- Click "Create a Bot User". (Discord API supports a few types of apps/bots, but we are building a bot)
- Locate your bot's user token. Your user token must not be shared with anyone. If it is posted publicly, change it ASAP.
- Please refer to the best practices for storing and managing connection tokens.
todo
- Please refer to the best practices for storing and managing connection tokens.
- Fork this repo.
- Clone your copy of this repo using
git clone https://github.com/USERNAME/CSSBot_Py.git
- Create a new file in your CSSBot_Py directory:
config.ini
- Populate the file with the following contents:
[Configuration] connection_token=XXXXXXXXXYOURTOKENGOESHEREXXXXXXX
Run the following command:
python3 main.py
The first lines should read something like:
using discordpy version 1.0.0a
Logged in SomeUser - 1234567890
Version 1.0.0a
When I run python3 main.py
I get this error.
TypeError: Inheritance a class <class 'aiohttp.http_writer.URL'> from URL is forbidden
Update your requirements.txt with the latest version from this repo with the latest contents. The file should contain:
yarl<1.2
git+https://github.com/Rapptz/discord.py@rewrite#egg=discord.py[voice]
Run your python3 -m pip install -r requirements.txt
(or equivalent) command again, then python3 main.py
.