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