Skip to content

Commit aac8d1a

Browse files
committed
testing slash command groups and subgroups
1 parent 2777823 commit aac8d1a

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

‎CS50/FinalProject/bot_app.py‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,31 @@
1111
bot = lightbulb.Bot(token=os.environ.get("DISCORD_BOT_TOKEN"), prefix="DisBot", logs="DEBUG")
1212

1313

14-
# Silly bot command definition
15-
class Echo(slash_commands.SlashCommand):
16-
description = "Repeats your input."
14+
class Foo(slash_commands.SlashCommandGroup):
15+
description = "Test slash command group."
16+
17+
18+
@Foo.subcommand()
19+
class Bar(slash_commands.SlashSubCommand):
20+
description = "Test subcommand."
21+
# Options
22+
baz: str = slash_commands.Option("Test subcommand option.")
23+
24+
async def callback(self, context):
25+
await context.respond(context.options.baz)
26+
27+
@Foo.subcommand()
28+
class Baz(slash_commands.SlashSubCommand):
29+
description = "Test subcommand 2."
1730
# Options
18-
text: str = slash_commands.Option("Text to repeat")
31+
bak: str = slash_commands.Option("Test subcommand option 2.")
1932

2033
async def callback(self, context):
21-
await context.respond(context.options.text)
34+
await context.respond(context.options.bak)
2235

2336

2437
# Add the slash command to the bot
25-
bot.add_slash_command(Echo)
38+
bot.add_slash_command(Foo)
2639

2740

2841
# Run the bot

0 commit comments

Comments
 (0)