Skip to content

Latest commit

 

History

History
72 lines (57 loc) · 2.46 KB

README.md

File metadata and controls

72 lines (57 loc) · 2.46 KB

Basic Bot Template

GitHub Actions Workflow Status GitHub Issues or Pull Requests GitHub License GitHub commit activity

This is a basic bot template for the Discord API using disnake.

Key Features

  • Neat packaging control.
  • Workflows for linting.
  • Basic bot setup.

Getting Started

  1. Clone the template here.
  2. Changing the license and changing the version and authors in pyproject.toml and src/__init__.py.
  3. Installing the dependencies:
python3 -m pip install poetry
poetry install
  1. Create a .env file in the root directory and add the following:
TOKEN=YOUR_BOT_TOKEN
  1. Update version and title in pyproject.toml and src/__init__.py.
  2. Run the bot: (Run exit to exit the shell.)
poetry shell
python main.py

Examples

Making a plugin:

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()

Using localization:

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.
),