SlashCommandManager
Class
Entry point for slash commands: declaration, execution, autocomplete and sync. Alias: SlashManager.
from discord_interactions import SlashCommandManagerAliases SlashManager
Constructor
SlashCommandManager( client: discord.Client, *, owner_ids: Set[int] | None = None, auto_sync: bool = True, sync_on_ready: bool = True, default_guilds: List[int] | None = None,)| Name | Type | Default | Description |
|---|---|---|---|
client | discord.Client | required | discord.Client or commands.Bot. |
owner_ids | Set[int] | None | None | Owners for @owner_only(); read from the application otherwise. |
auto_sync | bool | True | Sync commands on startup. |
sync_on_ready | bool | True | Sync on the ready event. |
default_guilds | List[int] | None | None | Guilds to sync to (instant) instead of globally. |
Methods
find_command
def find_command( data: Dict[str, Any],) -> Tuple[SlashCommand | None, List[Dict[str, Any]]]command
def command( name: str | None = None, description: str = 'No description', *, options: List[OptionBase] | None = None, guild_ids: List[int] | None = None, auto_defer: bool = False, defer_ephemeral: bool = False, ephemeral: bool = False, name_localizations: Dict[str, str] | None = None, description_localizations: Dict[str, str] | None = None, **kwargs: Any,) -> Callable[[~T], ~T]Decorator: declares a command.
group
def group( name: str, description: str = 'No description', *, guild_ids: List[int] | None = None, **kwargs: Any,) -> SlashGroupCreates a subcommand group.
add_middleware
def add_middleware(middleware: Middleware) -> NoneAdds a ready-made middleware.
remove_middleware
def remove_middleware(name: str) -> boolmiddleware
def middleware( name: str | None = None, *, priority: int = 100, commands: List[str] | None = None, exclude: List[str] | None = None,) -> CallableDecorator: before, after or error middleware, depending on the signature.
on_error
def on_error(func: Callable) -> CallableDecorator: error handler. Returning False lets the default handling run.
autocomplete
def autocomplete(command_name: str, option_name: str) -> CallableDecorator: autocomplete for an option.
build_payload
def build_payload() -> List[Dict[str, Any]]Commands in API format, without sending anything.
sync
async def sync(guilds: List[int] | None = None) -> Dict[int | None, Any]Replaces the commands on Discord, globally or per guild.
get_command
def get_command(name: str) -> SlashCommand | Noneget_all_commands
def get_all_commands() -> List[SlashCommand]get_group
def get_group(name: str) -> SlashGroup | Noneremove_command
def remove_command(name: str) -> boolExample
import discordfrom discord_interactions.slash import SlashManager client = discord.Client(intents=discord.Intents.default())slash = SlashManager(client, default_guilds=[123456789012345678]) @slash.command(description="Latence du bot")async def ping(ctx): await ctx.respond(f"Pong ! {ctx.bot.latency * 1000:.0f} ms") client.run(TOKEN)Details
client = discord.Client(intents=discord.Intents.default()) slash = SlashManager(client)
@slash.command(description="Latence du bot") async def ping(ctx):
await ctx.respond(f"Pong ! {ctx.bot.latency * 1000:.0f} ms")