Struct serenity::model::interactions::Interaction[][src]

#[non_exhaustive]pub struct Interaction {
    pub id: InteractionId,
    pub kind: InteractionType,
    pub data: Option<ApplicationCommandInteractionData>,
    pub guild_id: GuildId,
    pub channel_id: ChannelId,
    pub member: Member,
    pub token: String,
    pub version: u8,
}
This is supported on crate feature unstable_discord_api only.

Information about an interaction.

An interaction is sent when a user invokes a slash command and is the same for slash commands and other future interaction types.

Fields (Non-exhaustive)

Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct {{ .. }} syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
id: InteractionIdkind: InteractionTypedata: Option<ApplicationCommandInteractionData>guild_id: GuildIdchannel_id: ChannelIdmember: Membertoken: Stringversion: u8

Implementations

impl Interaction[src]

pub async fn create_global_application_command<F>(
    http: impl AsRef<Http>,
    application_id: u64,
    f: F
) -> Result<ApplicationCommand> where
    F: FnOnce(&mut CreateInteraction) -> &mut CreateInteraction
[src]

Creates a global ApplicationCommand, overriding an existing one with the same name if it exists.

When a created ApplicationCommand is used, the InteractionCreate event will be emitted.

Note: Global commands may take up to an hour to become available.

As such, it is recommended that guild application commands be used for testing purposes.

Examples

Create a simple ping command

use serenity::model::interactions::Interaction;

let application_id = 42; // usually this will be the bot's UserId

let _ = Interaction::create_global_application_command(&http, application_id, |a| {
   a.name("ping")
    .description("A simple ping command")
})
.await;

Create a command that echoes what is inserted

use serenity::model::interactions::{Interaction, ApplicationCommandOptionType};

let application_id = 42; // usually this will be the bot's UserId

let _ = Interaction::create_global_application_command(&http, application_id, |a| {
   a.name("echo")
    .description("What is said is echoed")
    .create_interaction_option(|o| {
        o.name("to_say")
         .description("What will be echoed")
         .kind(ApplicationCommandOptionType::String)
         .required(true)
    })
})
.await;

Errors

May return an Error::Http if the ApplicationCommand is illformed, such as if more than 10 choices are set. See the API Docs for further details.

Can also return an Error::Json if there is an error in deserializing the response.

pub async fn create_guild_application_command<F>(
    http: impl AsRef<Http>,
    guild_id: GuildId,
    application_id: u64,
    f: F
) -> Result<ApplicationCommand> where
    F: FnOnce(&mut CreateInteraction) -> &mut CreateInteraction
[src]

Creates a guild specific ApplicationCommand

Note: Unlike global ApplicationCommands, guild commands will update instantly.

Errors

Returns the same possible errors as create_global_application_command.

pub async fn create_interaction_response<F>(
    &self,
    http: impl AsRef<Http>,
    f: F
) -> Result<()> where
    F: FnOnce(&mut CreateInteractionResponse) -> &mut CreateInteractionResponse
[src]

Creates a response to the interaction received.

Note: Message contents must be under 2000 unicode code points.

Errors

Returns an Error::Model if the message content is too long. May also return an Error::Http if the API returns an error, or an Error::Json if there is an error in deserializing the API response.

Errors

pub async fn edit_original_interaction_response<F>(
    &self,
    http: impl AsRef<Http>,
    application_id: u64,
    f: F
) -> Result<Message> where
    F: FnOnce(&mut EditInteractionResponse) -> &mut EditInteractionResponse
[src]

Edits the initial interaction response.

application_id will usually be the bot’s [UserId], except in cases of bots being very old.

Refer to Discord’s docs for Edit Webhook Message for field information.

Note: Message contents must be under 2000 unicode code points, does not work on ephemeral messages.

Errors

Returns Error::Model if the edited content is too long. May also return Error::Http if the API returns an error, or an Error::Json if there is an error deserializing the response.

pub async fn delete_original_interaction_response(
    &self,
    http: impl AsRef<Http>,
    application_id: u64
) -> Result<()>
[src]

Deletes the initial interaction response.

Errors

May return Error::Http if the API returns an error. Such as if the response was already deleted.

pub async fn create_followup_message<'a, F>(
    &self,
    http: impl AsRef<Http>,
    application_id: u64,
    wait: bool,
    f: F
) -> Result<Option<Message>> where
    F: FnOnce(&'b mut CreateInteractionResponseFollowup<'a>) -> &'b mut CreateInteractionResponseFollowup<'a>, 
[src]

Creates a followup response to the response sent.

Note: Message contents must be under 2000 unicode code points.

Errors

Will return Error::Model if the content is too long. May also return Error::Http if the API returns an error, or a Error::Json if there is an error in deserializing the response.

Trait Implementations

impl Clone for Interaction[src]

impl Debug for Interaction[src]

impl<'de> Deserialize<'de> for Interaction[src]

impl Serialize for Interaction[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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