twilight_http/request/application/command/create_global_command/mod.rs
1mod chat_input;
2mod message;
3mod user;
4
5pub use self::{
6 chat_input::CreateGlobalChatInputCommand, message::CreateGlobalMessageCommand,
7 user::CreateGlobalUserCommand,
8};
9
10use crate::Client;
11use twilight_model::id::{marker::ApplicationMarker, Id};
12
13/// Create a new global command.
14#[must_use = "the command must have a type"]
15pub struct CreateGlobalCommand<'a> {
16 application_id: Id<ApplicationMarker>,
17 http: &'a Client,
18}
19
20impl<'a> CreateGlobalCommand<'a> {
21 pub(crate) const fn new(http: &'a Client, application_id: Id<ApplicationMarker>) -> Self {
22 Self {
23 application_id,
24 http,
25 }
26 }
27
28 /// Create a new chat input global command.
29 ///
30 /// The command name must only contain alphanumeric characters and lowercase
31 /// variants must be used where possible. Special characters `-` and `_` are
32 /// allowed. The description must be between 1 and 100 characters in length.
33 ///
34 /// Creating a command with the same name as an already-existing global
35 /// command will overwrite the old command. See
36 /// [Discord Docs/Create Global Application Command].
37 ///
38 /// # Errors
39 ///
40 /// Returns an error of type [`NameLengthInvalid`] or [`NameCharacterInvalid`]
41 /// if the command name is invalid.
42 ///
43 /// Returns an error of type [`DescriptionInvalid`] if the
44 /// command description is not between 1 and 100 characters.
45 ///
46 /// [`DescriptionInvalid`]: twilight_validate::command::CommandValidationErrorType::DescriptionInvalid
47 /// [`NameCharacterInvalid`]: twilight_validate::command::CommandValidationErrorType::NameCharacterInvalid
48 /// [`NameLengthInvalid`]: twilight_validate::command::CommandValidationErrorType::NameLengthInvalid
49 /// [Discord Docs/Create Global Application Command]: https://discord.com/developers/docs/interactions/application-commands#create-global-application-command
50 pub fn chat_input(
51 self,
52 name: &'a str,
53 description: &'a str,
54 ) -> CreateGlobalChatInputCommand<'a> {
55 CreateGlobalChatInputCommand::new(self.http, self.application_id, name, description)
56 }
57
58 /// Create a new message global command.
59 ///
60 /// Creating a command with the same name as an already-existing global
61 /// command will overwrite the old command. See
62 /// [Discord Docs/Create Global Application Command].
63 ///
64 /// # Errors
65 ///
66 /// Returns an error of type [`NameLengthInvalid`] if the command name is
67 /// not between 1 and 32 characters.
68 ///
69 /// [`NameLengthInvalid`]: twilight_validate::command::CommandValidationErrorType::NameLengthInvalid
70 /// [Discord Docs/Create Global Application Command]: https://discord.com/developers/docs/interactions/application-commands#create-global-application-command
71 pub fn message(self, name: &'a str) -> CreateGlobalMessageCommand<'a> {
72 CreateGlobalMessageCommand::new(self.http, self.application_id, name)
73 }
74
75 /// Create a new user global command.
76 ///
77 /// Creating a command with the same name as an already-existing global
78 /// command will overwrite the old command. See
79 /// [Discord Docs/Create Global Application Command].
80 ///
81 /// # Errors
82 ///
83 /// Returns an error of type [`NameLengthInvalid`] if the command name is
84 /// not between 1 and 32 characters.
85 ///
86 /// [`NameLengthInvalid`]: twilight_validate::command::CommandValidationErrorType::NameLengthInvalid
87 /// [Discord Docs/Create Global Application Command]: https://discord.com/developers/docs/interactions/application-commands#create-global-application-command
88 pub fn user(self, name: &'a str) -> CreateGlobalUserCommand<'a> {
89 CreateGlobalUserCommand::new(self.http, self.application_id, name)
90 }
91}