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
sourceimpl<'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 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()));
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 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
sourceimpl<'a> Clone for CommandInputData<'a>
impl<'a> Clone for CommandInputData<'a>
sourcefn clone(&self) -> CommandInputData<'a>
fn clone(&self) -> CommandInputData<'a>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<'a> Debug for CommandInputData<'a>
impl<'a> Debug for CommandInputData<'a>
sourceimpl From<CommandData> for CommandInputData<'_>
impl From<CommandData> for CommandInputData<'_>
sourcefn from(data: CommandData) -> Self
fn from(data: CommandData) -> Self
Converts to this type from the input type.
sourceimpl<'a> PartialEq<CommandInputData<'a>> for CommandInputData<'a>
impl<'a> PartialEq<CommandInputData<'a>> for CommandInputData<'a>
sourcefn eq(&self, other: &CommandInputData<'a>) -> bool
fn eq(&self, other: &CommandInputData<'a>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &CommandInputData<'a>) -> bool
fn ne(&self, other: &CommandInputData<'a>) -> bool
This method tests for !=
.
impl<'a> Eq for CommandInputData<'a>
impl<'a> StructuralEq for CommandInputData<'a>
impl<'a> StructuralPartialEq for CommandInputData<'a>
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more