Skip to main content

ComponentInteraction

Struct ComponentInteraction 

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

A component interaction given to a Client::component route (D-252): dereferences to the ComponentData (custom_id, values, users, …), with the args of its custom ID, and answers through InteractionExt (update, reply, show_modal, …).

discord.js counterpart: ButtonInteraction and the select menu interactions.

Implementations§

Source§

impl ComponentInteraction

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.

Source§

impl ComponentInteraction

Source

pub fn args(&self) -> &str

Returns the part of the custom ID after the route name and its : (D-254): "42" for vote:42, "a:b" for vote:a:b, "" for vote.

discord.js counterpart: none (discord.js leaves the customId to the bot).

§Examples
// A button with the custom ID `vote:42` votes for option 42.
client.component("vote", |ctx, button| async move {
    let option: u32 = button.args().parse()?;
    button.reply(&ctx, format!("You voted for {option}")).await?;
    Ok(())
});

Methods from Deref<Target = ComponentData>§

Source

pub fn ids<T>(&self) -> impl Iterator<Item = Id<T>>

Parses the selected values of a user, role, mentionable or channel select menu as IDs, skipping values that are not snowflakes.

discord.js counterpart: UserSelectMenuInteraction#values and its siblings.

Source

pub fn users(&self) -> impl Iterator<Item = &User>

Returns the users chosen in a user or mentionable select menu.

discord.js counterpart: UserSelectMenuInteraction#users.

Source

pub fn members(&self) -> impl Iterator<Item = (&User, &InteractionMember)>

Returns the users chosen in a user or mentionable select menu in a guild, with their member data.

discord.js counterpart: UserSelectMenuInteraction#members.

Source

pub fn roles(&self) -> impl Iterator<Item = &Role>

Returns the roles chosen in a role or mentionable select menu.

discord.js counterpart: RoleSelectMenuInteraction#roles.

Source

pub fn channels(&self) -> impl Iterator<Item = &InteractionChannel>

Returns the channels chosen in a channel select menu.

discord.js counterpart: ChannelSelectMenuInteraction#channels.

Source

pub fn mentionables(&self) -> impl Iterator<Item = Mentionable<'_>>

Returns the users and roles chosen in a mentionable select menu.

discord.js counterpart: MentionableSelectMenuInteraction (users, members, roles).

Trait Implementations§

Source§

impl Clone for ComponentInteraction

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 Collectable for ComponentInteraction

Source§

impl Debug for ComponentInteraction

Source§

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

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

impl Deref for ComponentInteraction

Source§

type Target = ComponentData

The resulting type after dereferencing.
Source§

fn deref(&self) -> &ComponentData

Dereferences the value.
Source§

impl InteractionExt for ComponentInteraction

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