Skip to content
/ bot-template Public template

A basic template for a discord bot with disnake.

License

Notifications You must be signed in to change notification settings

OseSem/bot-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

A basic template for a discord bot with disnake.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Languages