#Using flags in slash commands?

1 messages · Page 1 of 1 (latest)

spice frigate
#

I have a bunch of different moderation commands, all with the same basic arguments (target, reason, expires, no_dm). Can I coalesce these args in a FlagConverter to add them as options to slash commands, like this example, to reduce boilerplate code?

class ModActionFlags(FlagConverter):
    target: Member
    reason: str = None
    expires: DateTimeConverter = None
    no_dm: bool = False

@bot.slash_command()
async def ban(ctx: Context, flags: ModActionFlags):
    await ctx.guild.ban(flags.target, reason=f"{ctx.author}: {reason}")
    # etc, etc
    await ctx.respond(f"{flags.target} is now b&. 👍")
bronze thorn
#

bot.slash_command has an options kwarg you could use to declare options, then recieve them in the command parameters

spice frigate
bronze thorn
#

something like

cmd_options = [...]

@bot.slash_command(
    options=cmd_options,
)
async def foo(ctx, target, reason):
    ....
spice frigate