forked from serenity-rs/poise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubcommand_required.rs
34 lines (31 loc) · 1.38 KB
/
subcommand_required.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use crate::{Context, Error};
/// A command with two subcommands: `child1` and `child2`
///
/// Running this function directly, without any subcommand, is only supported in prefix commands.
/// Discord doesn't permit invoking the root command of a slash command if it has subcommands.
/// This command can be invoked only with `parent child1` and `parent child2`, due to `subcommand_required` parameter.
/// If you want to allow `parent` to be invoked without subcommand, remove `subcommand_required` parameter
#[poise::command(
prefix_command,
slash_command,
subcommands("child1", "child2"),
subcommand_required
)]
// Omit 'ctx' parameter here. It is not needed, because this function will never be called.
// TODO: Add a way to remove 'ctx' parameter, when `subcommand_required` is set
pub async fn parent_subcommand_required(_: Context<'_>) -> Result<(), Error> {
// This will never be called, because `subcommand_required` parameter is set
Ok(())
}
/// A subcommand of `parent`
#[poise::command(prefix_command, slash_command)]
pub async fn child1(ctx: Context<'_>) -> Result<(), Error> {
ctx.say("You invoked the first child command!").await?;
Ok(())
}
/// Another subcommand of `parent`
#[poise::command(prefix_command, slash_command)]
pub async fn child2(ctx: Context<'_>) -> Result<(), Error> {
ctx.say("You invoked the second child command!").await?;
Ok(())
}