#Create command without decorator

1 messages · Page 1 of 1 (latest)

frigid yew
#

Is there a way to define a command without using the interactions.Client.command decorator? I need to be able to dynamically create a bunch of commands from a config file without said config file being a python script.

Something like this would be great:

async def my_function(context):
  do stuff
bot.register_command(name = "...", description = "...", callback = my_function)

Is that possible?

long pastureBOT
#

Hey! Once your issue is solved, press the button below to close this thread!

dire horizon
#

You mean something like this? If so, then yes it should be possible because I took this example from the guides: https://interactions-py.github.io/interactions.py/Guides/03 Creating Commands/#__tabbed_2_4

from interactions import SlashCommandOption

async def my_command_function(ctx: SlashContext, integer_option: int):
    await ctx.send(f"You input {integer_option}")

bot.add_interaction(
    command=SlashCommand(
        name="my_command",
        description="My first command :)",
        options=[
            SlashCommandOption(
                name="integer_option",
                description="Integer Option",
                required=True,
                type=OptionType.INTEGER
            )
        ]
    )
)