#[non_exhaustive]pub struct CommandData {
pub id: CommandId,
pub name: CompactString,
pub kind: CommandType,
pub resolved: Option<Box<Resolved>>,
pub options: Vec<CommandDataOption>,
pub guild_id: Option<GuildId>,
pub target_id: Option<GenericId>,
}Expand description
The data of a command interaction (and of an autocomplete interaction).
discord.js counterpart: the command fields of CommandInteraction (commandId,
commandName, commandType, options).
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.id: CommandIdThe command’s ID.
name: CompactStringThe command’s name.
kind: CommandTypeThe command’s type.
resolved: Option<Box<Resolved>>The users, members, roles, channels, messages and attachments the options refer to (and the target of context menu commands).
options: Vec<CommandDataOption>The options the user filled in (in autocomplete interactions: possibly partial).
guild_id: Option<GuildId>The guild the command is registered in (guild commands).
target_id: Option<GenericId>The user or message a context menu command was used on (in resolved).
Implementations§
Source§impl CommandData
impl CommandData
Sourcepub fn focused(&self) -> Option<&CommandDataOption>
pub fn focused(&self) -> Option<&CommandDataOption>
Returns the option that is being typed in an autocomplete interaction, searching subcommands and groups.
discord.js counterpart: CommandInteractionOptionResolver#getFocused.
Source§impl CommandData
Reads command options by name and type (D-250).
impl CommandData
Reads command options by name and type (D-250).
The getters look at the options of the subcommand that was run (leaf_options), so
get_string("reason") works the same for /ban reason:… and /mod ban reason:…. User,
member, role, channel and attachment getters return the resolved
object behind the option’s ID.
§Examples
use djs_model::interaction::Interaction;
// `/mod warn reason:spam days:7`
let interaction: Interaction = serde_json::from_str(json).unwrap();
let data = interaction.command().unwrap();
assert_eq!(data.subcommand(), Some("warn"));
assert_eq!(data.get_string("reason"), Some("spam"));
assert_eq!(data.get_integer("days"), Some(7));
assert_eq!(data.get_boolean("silent"), None); // not filled in
assert_eq!(data.get_string("days"), None); // another typeSourcepub fn leaf_options(&self) -> &[CommandDataOption]
pub fn leaf_options(&self) -> &[CommandDataOption]
Returns the options of the subcommand that was run, or the command’s own options if it has no subcommands: the options every getter searches.
discord.js counterpart: the hoisted options of CommandInteractionOptionResolver.
Sourcepub fn subcommand(&self) -> Option<&str>
pub fn subcommand(&self) -> Option<&str>
Returns the name of the subcommand that was run (also inside a group).
discord.js counterpart: CommandInteractionOptionResolver#getSubcommand.
Sourcepub fn subcommand_group(&self) -> Option<&str>
pub fn subcommand_group(&self) -> Option<&str>
Returns the name of the subcommand group of the subcommand that was run.
discord.js counterpart: CommandInteractionOptionResolver#getSubcommandGroup.
Sourcepub fn get(&self, name: &str) -> Option<&CommandOptionValue>
pub fn get(&self, name: &str) -> Option<&CommandOptionValue>
Returns the value of the option name (among the leaf_options),
whatever its type.
discord.js counterpart: CommandInteractionOptionResolver#get.
Sourcepub fn get_string(&self, name: &str) -> Option<&str>
pub fn get_string(&self, name: &str) -> Option<&str>
Returns the value of the string option name.
discord.js counterpart: CommandInteractionOptionResolver#getString.
Sourcepub fn get_integer(&self, name: &str) -> Option<i64>
pub fn get_integer(&self, name: &str) -> Option<i64>
Returns the value of the integer option name.
discord.js counterpart: CommandInteractionOptionResolver#getInteger.
Sourcepub fn get_number(&self, name: &str) -> Option<f64>
pub fn get_number(&self, name: &str) -> Option<f64>
Returns the value of the number (floating-point) option name.
discord.js counterpart: CommandInteractionOptionResolver#getNumber.
Sourcepub fn get_boolean(&self, name: &str) -> Option<bool>
pub fn get_boolean(&self, name: &str) -> Option<bool>
Returns the value of the boolean option name.
discord.js counterpart: CommandInteractionOptionResolver#getBoolean.
Sourcepub fn get_user(&self, name: &str) -> Option<&User>
pub fn get_user(&self, name: &str) -> Option<&User>
Returns the user chosen in the user (or mentionable) option name.
discord.js counterpart: CommandInteractionOptionResolver#getUser.
Sourcepub fn get_member(&self, name: &str) -> Option<(&User, &InteractionMember)>
pub fn get_member(&self, name: &str) -> Option<(&User, &InteractionMember)>
Returns the user chosen in the user (or mentionable) option name with their member
data; None outside guilds or if the user is not a member.
discord.js counterpart: CommandInteractionOptionResolver#getMember.
Sourcepub fn get_role(&self, name: &str) -> Option<&Role>
pub fn get_role(&self, name: &str) -> Option<&Role>
Returns the role chosen in the role (or mentionable) option name.
discord.js counterpart: CommandInteractionOptionResolver#getRole.
Sourcepub fn get_channel(&self, name: &str) -> Option<&InteractionChannel>
pub fn get_channel(&self, name: &str) -> Option<&InteractionChannel>
Returns the channel chosen in the channel option name (a partial channel with the
invoking member’s permissions in it).
discord.js counterpart: CommandInteractionOptionResolver#getChannel.
Sourcepub fn get_attachment(&self, name: &str) -> Option<&Attachment>
pub fn get_attachment(&self, name: &str) -> Option<&Attachment>
Returns the file uploaded in the attachment option name.
discord.js counterpart: CommandInteractionOptionResolver#getAttachment.
Sourcepub fn get_mentionable(&self, name: &str) -> Option<Mentionable<'_>>
pub fn get_mentionable(&self, name: &str) -> Option<Mentionable<'_>>
Returns the user or role chosen in the mentionable option name.
discord.js counterpart: CommandInteractionOptionResolver#getMentionable.
Sourcepub fn focused_value(&self) -> Option<&str>
pub fn focused_value(&self) -> Option<&str>
Returns what the user has typed so far in the focused option of an
autocomplete interaction.
discord.js counterpart: CommandInteractionOptionResolver#getFocused.
Sourcepub fn target_user(&self) -> Option<&User>
pub fn target_user(&self) -> Option<&User>
Returns the user a user command was used on.
discord.js counterpart: UserContextMenuCommandInteraction#targetUser.
Sourcepub fn target_member(&self) -> Option<(&User, &InteractionMember)>
pub fn target_member(&self) -> Option<(&User, &InteractionMember)>
Returns the user a user command was used on with their member data (in guilds).
discord.js counterpart: UserContextMenuCommandInteraction#targetMember.
Sourcepub fn target_message(&self) -> Option<&Message>
pub fn target_message(&self) -> Option<&Message>
Returns the message a message command was used on.
discord.js counterpart: MessageContextMenuCommandInteraction#targetMessage.