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
//! Used for building commands to send to Discord.
pub mod permissions;
mod command_type;
mod option;
pub use self::{
command_type::CommandType,
option::{
BaseCommandOptionData, ChannelCommandOptionData, ChoiceCommandOptionData, CommandOption,
CommandOptionChoice, CommandOptionType, CommandOptionValue, NumberCommandOptionData,
OptionsCommandOptionData,
},
};
use crate::{
guild::Permissions,
id::{
marker::{ApplicationMarker, CommandMarker, CommandVersionMarker, GuildMarker},
Id,
},
};
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
/// Data sent to Discord to create a command.
///
/// [`CommandOption`]s that are required must be listed before optional ones.
/// Command names must be lower case, matching the Regex `^[\w-]{1,32}$`. See
/// [Discord Docs/Application Command Object].
///
/// This struct has an [associated builder] in the [`twilight-util`] crate.
///
/// [`twilight-util`]: https://docs.rs/twilight-util/latest/index.html
/// [associated builder]: https://docs.rs/twilight-util/latest/twilight_util/builder/command/struct.CommandBuilder.html
/// [Discord Docs/Application Command Object]: https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-structure
#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
pub struct Command {
#[serde(skip_serializing_if = "Option::is_none")]
pub application_id: Option<Id<ApplicationMarker>>,
/// Default permissions required for a member to run the command.
///
/// Setting this [`Permissions::empty()`] will prohibit anyone from running
/// the command, except for guild administrators.
pub default_member_permissions: Option<Permissions>,
/// Whether the command is available in DMs.
///
/// This is only relevant for globally-scoped commands. By default, commands
/// are visible in DMs.
#[serde(skip_serializing_if = "Option::is_none")]
pub dm_permission: Option<bool>,
/// Description of the command.
///
/// For [`User`] and [`Message`] commands, this will be an empty string.
///
/// [`User`]: CommandType::User
/// [`Message`]: CommandType::Message
pub description: String,
/// Localization dictionary for the `description` field.
///
/// See [Discord Docs/Localization].
///
/// [Discord Docs/Localization]: https://discord.com/developers/docs/interactions/application-commands#localization
#[serde(skip_serializing_if = "Option::is_none")]
pub description_localizations: Option<HashMap<String, String>>,
/// Guild ID of the command, if not global.
#[serde(skip_serializing_if = "Option::is_none")]
pub guild_id: Option<Id<GuildMarker>>,
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<Id<CommandMarker>>,
#[serde(rename = "type")]
pub kind: CommandType,
pub name: String,
/// Localization dictionary for the `name` field.
///
/// Keys should be valid locales. See [Discord Docs/Locales],
/// [Discord Docs/Localization].
///
/// [Discord Docs/Locales]: https://discord.com/developers/docs/reference#locales
/// [Discord Docs/Localization]: https://discord.com/developers/docs/interactions/application-commands#localization
#[serde(skip_serializing_if = "Option::is_none")]
pub name_localizations: Option<HashMap<String, String>>,
#[serde(default)]
pub options: Vec<CommandOption>,
/// Autoincrementing version identifier.
pub version: Id<CommandVersionMarker>,
}