- Ensure you have the dependencies required for discord.py https://discordpy.readthedocs.io/en/stable/intro.html#installing
sudo apt install libffi-dev libnacl-dev python3-dev python3.8-venv
- Create virtual environment
python3 -m venv .venv
- Activate virtual environment
source .venv/bin/activate
- Install requirements
pip install -r requirements.txt
- Copy
bot.json.example
tobot.json
and add any missing secrets - Update your bot.json to include the modules/cogs you want your bot to run
- Copy any .example configs in config/ and put in your values depending on which modules you load
python3 bcaus_bot.py
docker build . -t bcaus-bot:local
docker run --rm -it -v ${PWD}/data:/usr/src/app/data -v ${PWD}/config:/usr/src/app/config bcaus-bot:local
Create a new Cog in the cogs folder
from discord.ext import commands
import discord
import logging
class Testcog(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_ready(self):
# An example ready initializer
logging.info(f'Initialized: {__class__.__name__}')
@commands.Cog.listener()
async def on_message(self, msg: discord.Message):
# an example message listener with cogs
logging.info('MESSSAGE!')
@commands.command()
async def command(self, ctx, arg1: str):
# an example command with cogs
await ctx.send(f'You said {arg1}')
async def setup(bot):
await bot.add_cog(Testcog(bot))
Then register it to initialize in bcaus_bot.py
within the main method await bot.load_extension('cogs.cogclassname')
async def main():
async with bot:
...
await bot.load_extension('cogs.testcog')
...
await bot.start(config['botToken'])