Struct twilight_interactions::command::CommandInputData
source · [−]pub struct CommandInputData<'a> {
pub options: Vec<CommandDataOption>,
pub resolved: Option<Cow<'a, CommandInteractionDataResolved>>,
}Expand description
Data sent by Discord when receiving a command.
This type is used in the CommandModel trait. It can be initialized
from a CommandData using the From trait.
Fields
options: Vec<CommandDataOption>resolved: Option<Cow<'a, CommandInteractionDataResolved>>Implementations
pub fn parse_field<T>(&self, name: &str) -> Result<Option<T>, ParseError> where
T: CommandOption,
pub fn parse_field<T>(&self, name: &str) -> Result<Option<T>, ParseError> where
T: CommandOption,
Parse a field from the command data.
This method can be used to manually parse a field from
raw data, for example with guild custom commands. The
method return None if the field is not present instead
of returning an error.
Example
use twilight_interactions::command::CommandInputData;
// `options` is a Vec<CommandDataOption>
let data = CommandInputData { options, resolved: None };
let message = data.parse_field::<String>("message").unwrap();
assert_eq!(message, Some("Hello world".to_string()));Get the name of the focused field.
This method is useful when parsing commands with multiple autocomplete fields.
Example
use twilight_interactions::command::CommandInputData;
// `options` is a Vec<CommandDataOption>
let data = CommandInputData { options, resolved: None };
assert_eq!(data.focused(), Some("message"));pub fn from_option(
value: CommandOptionValue,
resolved: Option<&'a CommandInteractionDataResolved>
) -> Result<Self, ParseOptionErrorType>
pub fn from_option(
value: CommandOptionValue,
resolved: Option<&'a CommandInteractionDataResolved>
) -> Result<Self, ParseOptionErrorType>
Parse a subcommand CommandOptionValue.
This method signature is the same as the CommandOption trait,
except the explicit 'a lifetime. It is used when parsing subcommands.
Trait Implementations
Performs the conversion.
This method tests for self and other values to be equal, and is used
by ==. Read more
This method tests for !=.
Auto Trait Implementations
impl<'a> RefUnwindSafe for CommandInputData<'a>
impl<'a> Send for CommandInputData<'a>
impl<'a> Sync for CommandInputData<'a>
impl<'a> Unpin for CommandInputData<'a>
impl<'a> UnwindSafe for CommandInputData<'a>
Blanket Implementations
Mutably borrows from an owned value. Read more
Attaches the provided Subscriber to this type, returning a
WithDispatch wrapper. Read more
Attaches the current default Subscriber to this type, returning a
WithDispatch wrapper. Read more