Skip to main content

Modular slash command registry for Discord bots written in Python

Project description

slashcmdreg

A lightweight command registry for Discord.py bots using slash commands. Designed for modularity, simplicity, and zero boilerplate.

Installation

Install directly from PyPI:

pip install slashcmdreg

Overview

slashcmdreg allows you to define Discord slash commands as standalone Python files, each containing a setup() function that returns a SlashCommand object. The registry dynamically loads and syncs them with your bot.

Example Command

Create a file ping.py in your command folder:

from slashcmdreg import SlashCommand
import discord

def setup():
    async def callback(interaction: discord.Interaction):
        await interaction.response.send_message("pong")
    return SlashCommand("ping", "Replies with pong", callback)

```
Bot Integration

import discord
from discord.ext import commands
from slashcmdreg import load_commands

bot = commands.Bot(command_prefix="/", intents=discord.Intents.all())

@bot.event
async def on_ready():
    commands_loaded = load_commands(path="commands", package="commands")
    for cmd in commands_loaded:
        bot.tree.add_command(
            discord.app_commands.Command(
                name=cmd.name,
                description=cmd.description,
                callback=cmd.callback
            )
        )
    await bot.tree.sync()
    print(f"Synced {len(commands_loaded)} commands")

bot.run("YOUR_TOKEN")


Command Requirements

Each command file must:

- Be placed in the specified folder (commands folder)
- Contain a setup() function
- Return a SlashCommand object with:
- name: command name
- description: command description
- callback: async function with type-hinted parameters
License
MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slashcmdreg-4.3.1.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

slashcmdreg-4.3.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file slashcmdreg-4.3.1.tar.gz.

File metadata

  • Download URL: slashcmdreg-4.3.1.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for slashcmdreg-4.3.1.tar.gz
Algorithm Hash digest
SHA256 2127eaf740e8d8c9ce899fec195e71dc9fd7d49ce01cb6802f562dda89119115
MD5 f5e7b64bd81a44e92feb6d47de4777b0
BLAKE2b-256 6efd60dce2422c5697f23a29b605fabb93d1e2bf739079904d37d3155cd3d53d

See more details on using hashes here.

File details

Details for the file slashcmdreg-4.3.1-py3-none-any.whl.

File metadata

  • Download URL: slashcmdreg-4.3.1-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for slashcmdreg-4.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ff227dde9dd54e4ec27e8167e69cdc0005843d3fbd08ab85f61c978873c278c9
MD5 b1b04dbb292bec61c41a0126df04bbf8
BLAKE2b-256 6d75c1c78fb80544bf702b593c1e3e5410eabb20a984cba88d8ad7df26d9bc15

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page