twilight_model/application/interaction/application_command/
mod.rs

1//! [`ApplicationCommand`] interaction.
2//!
3//! [`ApplicationCommand`]: crate::application::interaction::InteractionType::ApplicationCommand
4
5mod option;
6
7pub use self::option::{CommandDataOption, CommandOptionValue};
8
9use crate::{
10    application::{command::CommandType, interaction::InteractionDataResolved},
11    id::{
12        marker::{CommandMarker, GenericMarker, GuildMarker},
13        Id,
14    },
15};
16use serde::{Deserialize, Serialize};
17
18/// Data received when an [`ApplicationCommand`] or [`ApplicationCommandAutocomplete`]
19/// interaction is executed.
20///
21/// See [Discord Docs/Application Command Data Structure].
22///
23/// [`ApplicationCommand`]: crate::application::interaction::InteractionType::ApplicationCommand
24/// [`ApplicationCommandAutocomplete`]: crate::application::interaction::InteractionType::ApplicationCommandAutocomplete
25/// [Discord Docs/Application Command Data Structure]: https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-application-command-data-structure
26#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
27pub struct CommandData {
28    /// ID of the guild the command is registered to.
29    #[serde(skip_serializing_if = "Option::is_none")]
30    pub guild_id: Option<Id<GuildMarker>>,
31    /// ID of the command.
32    pub id: Id<CommandMarker>,
33    /// Name of the command.
34    pub name: String,
35    /// Type of the command.
36    #[serde(rename = "type")]
37    pub kind: CommandType,
38    /// List of options specified by the user.
39    #[serde(default, skip_serializing_if = "Vec::is_empty")]
40    pub options: Vec<CommandDataOption>,
41    /// Resolved data from the interaction's options.
42    #[serde(skip_serializing_if = "Option::is_none")]
43    pub resolved: Option<InteractionDataResolved>,
44    /// If this is a user or message command, the ID of the targeted user/message.
45    #[serde(skip_serializing_if = "Option::is_none")]
46    pub target_id: Option<Id<GenericMarker>>,
47}