This is a basic bot template for the Discord API using disnake.
- Neat packaging control.
- Workflows for linting.
- Basic bot setup.
- Clone the template here.
- Changing the license and changing the version and authors in
pyproject.toml
andsrc/__init__.py
. - Installing the dependencies:
python3 -m pip install poetry
poetry install
- Create a
.env
file in the root directory and add the following:
TOKEN=YOUR_BOT_TOKEN
- Update version and title in
pyproject.toml
andsrc/__init__.py
. - Run the bot: (Run
exit
to exit the shell.)
poetry shell
python main.py
This template uses disnake.ext.plugins
to nicely split bot's functionality into multiple files. Plugins are conceptually similar to cogs, but offer a simplified interface and don't rely on various hacks that cogs use internally.
import disnake
from disnake.ext import plugins as p
from src.bot import Bot
plugin = p.Plugin[Bot]()
@plugin.slash_command()
async def example(_: disnake.CommandInteraction) -> None:
"""Parent Interaction Example."""
@example.sub_command(name="ping")
async def example_ping(inter: disnake.CommandInteraction) -> None:
"""Ping, Pong! [USAGE: /example ping]."""
await inter.response.send_message("Pong!")
setup, teardown = plugin.create_extension_handlers()
Our template utilizated disnake's built-in i18n with our own small function that formats them with the arguments provided.
plugin.bot.localization.get(
"{member}'s money:", # Default message if no language is found.
inter.locale, # The locale from the user found in the interaction
"BALANCE_CHECK", # The key to the translated message
member=member.display_name, # All formatted parameters go here.
),