Package: create-discord-bot
create-discord-bot - CLI to setup functional discord bot environmentThe 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 fileLog all discordpy related information into a fileLog all other logs to console during developmentCreate discordpy CogsDefault Admin Cog enabled with the functionality to:Unload CogsLoad CogsReload CogsSet Bot presenceCreate commands, which are uncategorisedautomatically load Cogs and Commands from filespossible disabling of Cogs and Command loadingpre-created unittest files (no unittest framework enforced!)switch between MVC structure and bare Cog setupDEBUG switch for developmentMultiple .env file supportDockerfile and docker-compose creation for both development and productionpredefined .gitignore for python development and for ignoring irrelevant files in projectfully documentedThe 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 usesdiscordpyfor the actual bot development. It also usesPyYamltosafe_loadthelogger.ymlfile. And lastly it usespython-dotenvto load the debug/development.envfile, when
not using docker during development.By default voice support fordiscordpyis 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.InstallationInstall the package globallypip install create-discord-botInstall the package in a virtual environmentvirtualenv .venv
. .venv/bin/activate
pip install creatediscordbotInstructions to setup demo projectCreate a new project folderCreate a virtual environment folder in there (highly recommended!)runcreate-discord-bot createbot animalsto create a new discord bot folder namedanimalsReplaceanimalswith your actual bot nameCheck 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.conf5.Create a.env.debugfile in the botfolderanimalsand 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.debugfile viaDISCORD_BOT_TOKEN=7.Install the requirements via pip:pip install -r animals/requirements.txt8.Run the following command:DEBUG=True python animals/main.pyto start your botRequirements:python 3.6UsageShow Help# --help also works
create-discord-bot -hCreate new botcreate-discord-bot createbot animalsCreates 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.1You 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.txtCreate new CogTo create a new cog module for the bot you can usecreatecog <cogname>. By default this creates a new Cog with
a controller file, a model file, a converter file and a folder withtestsfor 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.confand setcog_bare_default=True. This sets the--bareparameter 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 --testsIf you do not want to create the unittests in a full setup you can use--teststo 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.confand setcog_create_unittests_default=False. This sets the--testsparameter as defaultDockerise the deploymentcreate-discord-bot makedockerIf you want to deploy your bot via docker container than you can callmakedocker. This will create three files
for you:# In the Bot folder
- Dockerfile
# In the Project folder
- docker-compose.yml
- docker-compose-dev.ymlTheDockerfilein the bot folder usespython 3.8.2as a base image and copies your bot folder and installs
therequirements.txtpip requirements.To start the bot you can usedocker-compose up --buildfor production,
ordocker-compose -f docker-compose-dev.yml up --buildfor development/testing.The docker-compose configuration files have the.envand.env.debugfiles set as their environment files.If there are already docker related files it will ask you, if you wanted to overwrite them.LicenseGNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007