Skip to content

Slash Commands

Shell edited this page Jan 22, 2024 · 3 revisions

Introduction to Slash commands

Ok quick note, selfbots can't actually have their own slash commands, this section is for triggering slash commands of bots. Methods for slash commands are under channels.py. They're pretty simple I think, compared to the old selfcord I feel like it's been improved a lot.

Methods

Gets a list or a specific slash command if name is specified.

async def get_slash_commands(self, name: Optional[str] = None) -> Optional[SlashCommand] | Optional[list[SlashCommand]]

Triggers the slash command, takes the slash command object

async def trigger_slash(self, cmd: SlashCommand):

More explanation on attributes and methods here

Examples

This is for a command which doesn't take any arguments at all, is simply triggered like this.

@bot.cmd()
async def bump(ctx):
  cmd = await ctx.channel.get_slash_commands(name="Bump")
  await ctx.channel.trigger_slash(cmd)

For a command that is a subcommand of autofeeds. This is a command for carlbot. The subcommand also has some extra options, such as role, duration and message.

Reconstruct is required to push all the values back into the main slash command.

@bot.cmd(description="Test command")
async def test(ctx):
    cmd = await ctx.channel.get_slash_commands(name="autofeeds")
    
    option = cmd.get_option("create") # Get the subcommand
    # Add values
    option.add_value("role", "1189367094433820712")
    option.add_value("duration", "3 days")
    option.add_value("message", "YOUR MOM")
    # Push values back into the command
    option.reconstruct()

    # Trigger slash
    await ctx.channel.trigger_slash(cmd)
Clone this wiki locally