-
Notifications
You must be signed in to change notification settings - Fork 119
/
choice_parameter.rs
54 lines (49 loc) · 1.7 KB
/
choice_parameter.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use crate::{Context, Error};
#[derive(Debug, poise::ChoiceParameter)]
pub enum MyStringChoice {
#[name = "The first choice"]
A,
#[name = "The second choice"]
#[name = "A single choice can have multiple names"]
B,
// If no name is given, the variant name is used
C,
}
/// Dummy command to test slash command choice parameters
#[poise::command(prefix_command, slash_command)]
pub async fn choice(
ctx: Context<'_>,
#[description = "The choice you want to choose"] choice: MyStringChoice,
) -> Result<(), Error> {
ctx.say(format!("You entered {:?}", choice)).await?;
Ok(())
}
// For simple choices, you can also declare the options inline
//
// Features: supports duplicate options and theoretically any type that implements Display
//
// Limitations: due to macro limitations (partially self-imposed, partially external), poise
// currently does not support Options parameters, and only supports parameter types that can be
// constructed from a literal (https://doc.rust-lang.org/reference/expressions/literal-expr.html).
#[poise::command(slash_command)]
pub async fn inline_choice(
ctx: Context<'_>,
#[description = "Which continent are you from"]
#[choices("Europe", "Asia", "Africa", "America", "Australia", "Antarctica")]
continent: &'static str,
) -> Result<(), Error> {
ctx.say(format!("{} is a great continent!", continent))
.await?;
Ok(())
}
#[poise::command(slash_command)]
pub async fn inline_choice_int(
ctx: Context<'_>,
#[description = "Choose a number"]
#[choices(1, 2, 3, 4, 5, 4, 3, 2, 1)]
number: u32,
) -> Result<(), Error> {
ctx.say(format!("You chose {}... for better or for worse", number))
.await?;
Ok(())
}