pub struct CommandInputData<'a> {
pub options: Vec<CommandDataOption>,
pub resolved: Option<Cow<'a, InteractionDataResolved>>,
}Expand description
Data sent by Discord when receiving a command.
This type is used in the CommandModel trait. It can be initialized
from CommandData using the From trait.
Fields§
§options: Vec<CommandDataOption>§resolved: Option<Cow<'a, InteractionDataResolved>>Implementations§
Source§impl<'a> CommandInputData<'a>
impl<'a> CommandInputData<'a>
Sourcepub 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 returns 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()));Sourcepub fn focused(&self) -> Option<&str>
pub fn focused(&self) -> Option<&str>
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"));Sourcepub fn from_option(
value: CommandOptionValue,
resolved: Option<&'a InteractionDataResolved>,
) -> Result<Self, ParseOptionErrorType>
pub fn from_option( value: CommandOptionValue, resolved: Option<&'a InteractionDataResolved>, ) -> Result<Self, ParseOptionErrorType>
Parse a subcommand’s CommandOptionValue.
This method’s signature is the same as the CommandOption trait,
except for the explicit 'a lifetime. It is used when parsing
subcommands.
Trait Implementations§
Source§impl<'a> Clone for CommandInputData<'a>
impl<'a> Clone for CommandInputData<'a>
Source§fn clone(&self) -> CommandInputData<'a>
fn clone(&self) -> CommandInputData<'a>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<'a> Debug for CommandInputData<'a>
impl<'a> Debug for CommandInputData<'a>
Source§impl From<CommandData> for CommandInputData<'_>
impl From<CommandData> for CommandInputData<'_>
Source§fn from(data: CommandData) -> Self
fn from(data: CommandData) -> Self
Converts to this type from the input type.
Source§impl<'a> PartialEq for CommandInputData<'a>
impl<'a> PartialEq for CommandInputData<'a>
impl<'a> StructuralPartialEq for CommandInputData<'a>
Auto Trait Implementations§
impl<'a> Freeze for CommandInputData<'a>
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§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more