Skip to main content

create-discord-bot - CLI to setup functional discord bot environment

The create-discord-bot CLI tool allows you to quickly create a discord bot from stratch with a predefined project structure. You can also quickly create new Cogs, uncategorised commands or dockerise the entire bot.

The bot project has the following features upon creation:

  • Logging enabled with custom logger support via config file
  • Log all discordpy related information into a file
  • Log all other logs to console during development
  • Create discordpy Cogs
  • Default Admin Cog enabled with the functionality to:
    • Unload Cogs
    • Load Cogs
    • Reload Cogs
    • Set Bot presence
  • Create commands, which are uncategorised
  • automatically load Cogs and Commands from files
  • possible disabling of Cogs and Command loading
  • pre-created unittest files (no unittest framework enforced!)
  • switch between MVC structure and bare Cog setup
  • DEBUG switch for development
  • Multiple .env file support
  • Dockerfile and docker-compose creation for both development and production
  • predefined .gitignore for python development and for ignoring irrelevant files in project
  • fully documented

The intention is to quickly setup a new discord bot project. You do not need to dockerise the bot to run it. Since every line is documented it should be straightforward to change/add/remove behaviour to your preferences.

The project uses discordpy for the actual bot development. It also uses PyYaml to safe_load the logger.yml file. And lastly it uses python-dotenv to load the debug/development .env file, when not using docker during development.

By default voice support for discordpy is not in the requirements.txt. You need to install it as described in the official documentation. This is only required, if you want your bot to use voice in voice channels, i.e. playing music.

Installation

Install the package globally

pip install create-discord-bot

Install the package in a virtual environment

virtualenv .venv
. .venv/bin/activate
pip install creatediscordbot

Instructions to setup demo project

  1. Create a new project folder

  2. Create a virtual environment folder in there (highly recommended!)

  3. run create-discord-bot createbot animals to create a new discord bot folder named animals Replace animals with your actual bot name

  4. Check that the following folder & file structure has been created successfully:

├── animals
│   ├── cogs
│   │   ├── __init__.py
│   │   ├── admin
│   │   │   ├── __init__.py
│   │   │   ├── admin.py
│   │   │   ├── controller.py
│   │   │   ├── converter.py
│   │   │   ├── model.py
│   │   │   └── tests
│   │   │       ├── __init__.py
│   │   │       ├── test_controller.py
│   │   │       ├── test_converter.py
│   │   │       └── test_model.py
│   │   └── animals
│   │       ├── __init__.py
│   │       ├── animals.py
│   │       ├── controller.py
│   │       ├── converter.py
│   │       ├── model.py
│   │       └── tests
│   │           ├── __init__.py
│   │           ├── test_controller.py
│   │           ├── test_converter.py
│   │           └── test_model.py
│   ├── logger.yml
│   ├── main.py
│   ├── requirements.txt
│   ├── settings.py
│   ├── settings_files
│   │   ├── __init__.py 
│   │   ├── _global.py
│   │   ├── development.py
│   │   └── production.py
│   └── uncategorised_commands
│       ├── __init__.py
│       └── loader.py
├── logs
└── .creatediscordbot.conf

5.Create a .env.debug file in the botfolder animals and paste the following code in:

DISCORD_BOT_TOKEN=


DB_HOST_NAME=
DB_DATABASE_NAME=
DB_USER=
DB_PASSWORD=

(Note: for production just call the file .env - Both are specified in .gitignore and will not be committed to the repository you are using)

6.Supply your Discord Bot Token to the .env.debug file via DISCORD_BOT_TOKEN=

7.Install the requirements via pip:

pip install -r animals/requirements.txt

8.Run the following command: DEBUG=True python animals/main.py to start your bot

Requirements:

python 3.6

Usage

Show Help

# --help also works
create-discord-bot -h 

Create new bot

create-discord-bot createbot animals

Creates a new bot project with the project structure seen in the instructions section.

The discordpy bot will have the following requirements:

aiohttp==3.6.2
async-timeout==3.0.1
attrs==19.3.0
chardet==3.0.4
discord.py==1.3.3
idna==2.9
multidict==4.7.5
python-dotenv==0.13.0
websockets==8.1
yarl==1.4.2
PyYAML==5.3.1

You will find them in the requirements.txt that is generated with the project. You should then install them via pip:

pip install -r botfolder/requirements.txt

Create new Cog

To create a new cog module for the bot you can use createcog <cogname>. By default this creates a new Cog with a controller file, a model file, a converter file and a folder with tests for unittests.

If you do not want these you can supply the parameter --bare.

If you want to overwrite the default behaviour to NOT create a full Cog structure open your .creatediscordbot.conf and set cog_bare_default=True. This sets the --bare parameter as default

# --bare at the end prevents creation of unittests folder, controller/model and converter
create-discord-bot createcog cat
create-discord-bot createcog fish --bare
create-discord-bot createcog dog --tests

If you do not want to create the unittests in a full setup you can use --tests to prevent the creation of the test folder.

If you want to overwrite the default behaviour to NOT unittests in a full Cog structure open your .creatediscordbot.conf and set cog_create_unittests_default=False. This sets the --tests parameter as default

Dockerise the deployment

create-discord-bot makedocker

If you want to deploy your bot via docker container than you can call makedocker. This will create three files for you:

# In the Bot folder
- Dockerfile
# In the Project folder
- docker-compose.yml
- docker-compose-dev.yml

The Dockerfile in the bot folder uses python 3.8.2 as a base image and copies your bot folder and installs the requirements.txt pip requirements.

To start the bot you can use docker-compose up --build for production, or docker-compose -f docker-compose-dev.yml up --build for development/testing.

The docker-compose configuration files have the .env and .env.debug files set as their environment files.

If there are already docker related files it will ask you, if you wanted to overwrite them.

License

GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007

Release files for create-discord-bot 0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for create-discord-bot 0.10
File Size Uploaded
create-discord-bot-0.10.tar.gz 16.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for create-discord-bot 0.10
File Interpreter ABI Platform
create_discord_bot-0.10-py3-none-any.whl Python 3 none any Details

Total release size: 52.9 kB

Release files / create-discord-bot-0.10.tar.gz

Download URL create-discord-bot-0.10.tar.gz
Size 16.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9b103f7e56362b0cee5ceec15d8eb03f1734d117357adeb4f34c7ac5e9a05b18
BLAKE2b-256 checksum
How to use checksums
02751604e4d17296ec1973e6ebdfa838ea0974390e1d8bde8cd1c32313905735
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

Release files / create_discord_bot-0.10-py3-none-any.whl

Download URL create_discord_bot-0.10-py3-none-any.whl
Size 36.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2c357efd9089980166fa98abee9982171f0441d8f00fa36dfc15d959b8c694df
BLAKE2b-256 checksum
How to use checksums
17c4fad85f32ceaf2b862fa5cb8bbd231dea8cfb88392587f44e591e1b7ef112
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.10 This release

2 release files

0.9

2 release files

0.8

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page