Skip to main content

CommandInteraction

Struct CommandInteraction 

Source
pub struct CommandInteraction { /* private fields */ }
Expand description

A command interaction given to a Client::command route (D-252): dereferences to the CommandData (get_string, subcommand, …) and answers through InteractionExt (reply, defer_reply, …).

discord.js counterpart: ChatInputCommandInteraction and the context menu command interactions.

Implementations§

Source§

impl CommandInteraction

Source

pub fn interaction(&self) -> &Interaction

Returns the whole interaction: its guild, channel, member, locale, …

discord.js counterpart: the interaction itself (discord.js routes nothing).

Source

pub const fn event(&self) -> &Arc<InteractionCreate> ⓘ

Returns the event payload, shared with the InteractionCreate handlers.

discord.js counterpart: the event’s arguments.

Methods from Deref<Target = CommandData>§

Source

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

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.

Source

pub fn subcommand(&self) -> Option<&str>

Returns the name of the subcommand that was run (also inside a group).

discord.js counterpart: CommandInteractionOptionResolver#getSubcommand.

Source

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.

Source

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.

Source

pub fn get_string(&self, name: &str) -> Option<&str>

Returns the value of the string option name.

discord.js counterpart: CommandInteractionOptionResolver#getString.

Source

pub fn get_integer(&self, name: &str) -> Option<i64>

Returns the value of the integer option name.

discord.js counterpart: CommandInteractionOptionResolver#getInteger.

Source

pub fn get_number(&self, name: &str) -> Option<f64>

Returns the value of the number (floating-point) option name.

discord.js counterpart: CommandInteractionOptionResolver#getNumber.

Source

pub fn get_boolean(&self, name: &str) -> Option<bool>

Returns the value of the boolean option name.

discord.js counterpart: CommandInteractionOptionResolver#getBoolean.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn get_attachment(&self, name: &str) -> Option<&Attachment>

Returns the file uploaded in the attachment option name.

discord.js counterpart: CommandInteractionOptionResolver#getAttachment.

Source

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.

Source

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.

Source

pub fn target_user(&self) -> Option<&User>

Returns the user a user command was used on.

discord.js counterpart: UserContextMenuCommandInteraction#targetUser.

Source

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.

Source

pub fn target_message(&self) -> Option<&Message>

Returns the message a message command was used on.

discord.js counterpart: MessageContextMenuCommandInteraction#targetMessage.

Trait Implementations§

Source§

impl Clone for CommandInteraction

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CommandInteraction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for CommandInteraction

Source§

type Target = CommandData

The resulting type after dereferencing.
Source§

fn deref(&self) -> &CommandData

Dereferences the value.
Source§

impl InteractionExt for CommandInteraction

Source§

fn reply<B: Backend>( &self, ctx: &Context<B>, body: impl Into<MessageCallbackData>, ) -> impl Future<Output = Result<(), Error>> + Send

Responds with a message (ChannelMessageWithSource); accepts anything that converts into MessageCallbackData, such as &str. Set MessageFlags::EPHEMERAL in its flags for a message only the user sees. Read more
Source§

fn defer_reply<B: Backend>( &self, ctx: &Context<B>, flags: MessageFlags, ) -> impl Future<Output = Result<(), Error>> + Send

Acknowledges the interaction and shows “thinking…” (DeferredChannelMessageWithSource); the message follows with edit_reply. flags can only be MessageFlags::EPHEMERAL (for an ephemeral message) or empty. Read more
Source§

fn update<B: Backend>( &self, ctx: &Context<B>, body: impl Into<MessageCallbackData>, ) -> impl Future<Output = Result<(), Error>> + Send

Edits the message the component is on (UpdateMessage): fields left None keep their value. Component interactions and modals opened from a component. Read more
Source§

fn defer_update<B: Backend>( &self, ctx: &Context<B>, ) -> impl Future<Output = Result<(), Error>> + Send

Acknowledges a component interaction without a loading state (DeferredUpdateMessage); the message can be edited later with edit_reply. Read more
Source§

fn show_modal<B: Backend>( &self, ctx: &Context<B>, modal: ModalCallbackData, ) -> impl Future<Output = Result<(), Error>> + Send

Opens a modal (Modal), for example one built with djs_builders::ModalBuilder. Its submission arrives as a new interaction. Not for modal-submit and autocomplete interactions. Read more
Source§

fn respond<B: Backend>( &self, ctx: &Context<B>, choices: AutocompleteChoices, ) -> impl Future<Output = Result<(), Error>> + Send

Suggests choices for the option being typed in an autocomplete interaction (AutocompleteResult); up to 25, typed like the option. An empty list shows “no suggestions”. Read more
Source§

fn launch_activity<B: Backend>( &self, ctx: &Context<B>, ) -> impl Future<Output = Result<(), Error>> + Send

Launches the app’s Activity (LaunchActivity; apps with Activities enabled). Read more
Source§

fn fetch_reply<B: Backend>( &self, ctx: &Context<B>, ) -> impl Future<Output = Result<Arc<CachedMessage>, Error>> + Send

The message of the initial response (Get Original Interaction Response). Read more
Source§

fn edit_reply<B: Backend>( &self, ctx: &Context<B>, body: impl Into<EditWebhookMessage>, ) -> impl Future<Output = Result<Arc<CachedMessage>, Error>> + Send

Edits the message of the initial response — also how the message of a defer_reply is sent, and how a defer_updated message is edited (Edit Original Interaction Response). Accepts anything that converts into an EditWebhookMessage, such as &str. Read more
Source§

fn delete_reply<B: Backend>( &self, ctx: &Context<B>, ) -> impl Future<Output = Result<(), Error>> + Send

Deletes the message of the initial response (Delete Original Interaction Response). Read more
Source§

fn follow_up<B: Backend>( &self, ctx: &Context<B>, body: impl Into<CreateFollowupMessage>, ) -> impl Future<Output = Result<Arc<CachedMessage>, Error>> + Send

Sends another message for the interaction (Create Followup Message); accepts anything that converts into a CreateFollowupMessage, such as &str. After a defer_reply, the first follow-up replaces “thinking…”. Read more
Source§

fn fetch_follow_up<B: Backend>( &self, ctx: &Context<B>, message_id: MessageId, ) -> impl Future<Output = Result<Arc<CachedMessage>, Error>> + Send

A follow-up message (Get Followup Message). Read more
Source§

fn edit_follow_up<B: Backend>( &self, ctx: &Context<B>, message_id: MessageId, body: impl Into<EditWebhookMessage>, ) -> impl Future<Output = Result<Arc<CachedMessage>, Error>> + Send

Edits a follow-up message (Edit Followup Message); accepts anything that converts into an EditWebhookMessage, such as &str. Read more
Source§

fn delete_follow_up<B: Backend>( &self, ctx: &Context<B>, message_id: MessageId, ) -> impl Future<Output = Result<(), Error>> + Send

Deletes a follow-up message (Delete Followup Message). Read more
Source§

fn component_collector<B: Backend>( &self, ctx: &Context<B>, ) -> CollectorBuilder<ComponentInteraction>

A collector of the component interactions on this interaction’s reply (and its follow-ups), matched by the interaction they belong to: no need to fetch the reply. For a component interaction (whose response edits its message), the components of that message. Read more
Source§

fn await_component<B: Backend>( &self, ctx: &Context<B>, ) -> CollectorBuilder<ComponentInteraction, First>

Waits for one component interaction on this interaction’s reply (D-268); set a time. Read more
Source§

fn await_modal_submit<B: Backend>( &self, ctx: &Context<B>, time: Duration, ) -> CollectorBuilder<ModalInteraction, First>

Waits up to time for the user of this interaction to submit a modal (D-268), usually the one shown with show_modal. Add a filter on the modal’s custom_id when several can be open. time is required, as in discord.js: a closed modal sends nothing. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Classify for T

§

type Classified = T

§

fn classify(self) -> T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Declassify for T

§

type Declassified = T

§

fn declassify(self) -> T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more