twilight_http/request/application/command/create_guild_command/mod.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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
mod chat_input;
mod message;
mod user;
pub use self::{
chat_input::CreateGuildChatInputCommand, message::CreateGuildMessageCommand,
user::CreateGuildUserCommand,
};
use crate::Client;
use twilight_model::id::{
marker::{ApplicationMarker, GuildMarker},
Id,
};
/// Create a new command in a guild.
#[must_use = "the command must have a type"]
pub struct CreateGuildCommand<'a> {
application_id: Id<ApplicationMarker>,
guild_id: Id<GuildMarker>,
http: &'a Client,
}
impl<'a> CreateGuildCommand<'a> {
pub(crate) const fn new(
http: &'a Client,
application_id: Id<ApplicationMarker>,
guild_id: Id<GuildMarker>,
) -> Self {
Self {
application_id,
guild_id,
http,
}
}
/// Create a chat input command in a guild.
///
/// The command name must only contain alphanumeric characters and lowercase
/// variants must be used where possible. Special characters `-` and `_` are
/// allowed. The description must be between 1 and 100 characters in length.
///
/// Creating a guild command with the same name as an already-existing guild
/// command in the same guild will overwrite the old command. See
/// [Discord Docs/Create Guild Application Command].
///
/// # Errors
///
/// Returns an error of type [`NameLengthInvalid`] or [`NameCharacterInvalid`]
/// if the command name is invalid.
///
/// Returns an error of type [`DescriptionInvalid`] error type if the
/// command description is not between 1 and 100 characters.
///
/// [`DescriptionInvalid`]: twilight_validate::command::CommandValidationErrorType::DescriptionInvalid
/// [`NameCharacterInvalid`]: twilight_validate::command::CommandValidationErrorType::NameCharacterInvalid
/// [`NameLengthInvalid`]: twilight_validate::command::CommandValidationErrorType::NameLengthInvalid
/// [Discord Docs/Create Guild Application Command]: https://discord.com/developers/docs/interactions/application-commands#create-guild-application-command
pub fn chat_input(
self,
name: &'a str,
description: &'a str,
) -> CreateGuildChatInputCommand<'a> {
CreateGuildChatInputCommand::new(
self.http,
self.application_id,
self.guild_id,
name,
description,
)
}
/// Create a message command in a guild.
///
/// Creating a guild command with the same name as an already-existing guild
/// command in the same guild will overwrite the old command. See
/// [Discord Docs/Create Guild Application Command].
///
/// # Errors
///
/// Returns an error of type [`NameLengthInvalid`] if the command name is
/// not between 1 and 32 characters.
///
/// [`NameLengthInvalid`]: twilight_validate::command::CommandValidationErrorType::NameLengthInvalid
/// [Discord Docs/Create Guild Application Command]: https://discord.com/developers/docs/interactions/application-commands#create-guild-application-command
pub fn message(self, name: &'a str) -> CreateGuildMessageCommand<'a> {
CreateGuildMessageCommand::new(self.http, self.application_id, self.guild_id, name)
}
/// Create a user command in a guild.
///
/// Creating a guild command with the same name as an already-existing guild
/// command in the same guild will overwrite the old command. See
/// [Discord Docs/Create Guild Application Command].
///
/// # Errors
///
/// Returns an error of type [`NameLengthInvalid`] if the command name is
/// not between 1 and 32 characters.
///
/// [`NameLengthInvalid`]: twilight_validate::command::CommandValidationErrorType::NameLengthInvalid
/// [Discord Docs/Create Guild Application Command]: https://discord.com/developers/docs/interactions/application-commands#create-guild-application-command
pub fn user(self, name: &'a str) -> CreateGuildUserCommand<'a> {
CreateGuildUserCommand::new(self.http, self.application_id, self.guild_id, name)
}
}