An extension module for discord.py that facilitates class-based creation of Discord application commands.
- discord.py: Docs and various code snippets.
- IAmTomahawkx: Initial idea and design.
- Modern Pythonic API using
async
andawait
. - Proper rate limit handling.
- Optimised in both speed and memory.
- Fully compatible with discord.py's application command implementation without monkey-patching.
Python 3.8 or higher is required
To install the extension, you can just run the following command:
# Linux/macOS
python3 -m pip install -U discord-class-commands
# Windows
py -3 -m pip install -U discord-class-commands
To install the development version, do the following:
$ git clone https://github.com/dolfies/discord-class-commands
$ cd discord.py
$ python3 -m pip install -U .
This extension depends on version 2.0 of discord.py or a compatible fork.
import discord
from discord.ext import class_commands
client = discord.Client(intents=discord.Intents.default())
tree = discord.app_commands.CommandTree(client)
@client.event
async def setup_hook():
await tree.sync()
class Ping(class_commands.SlashCommand):
async def callback(self):
await self.send(f'Pong!')
tree.add_command(Ping)
client.run('token')
You can find more examples in the examples directory.