Package discord4j.core.object.command
Class Interaction
- java.lang.Object
-
- discord4j.core.object.command.Interaction
-
- All Implemented Interfaces:
DiscordObject
@Experimental public class Interaction extends Object implements DiscordObject
A Discord interaction.- See Also:
- Interaction Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classInteraction.TypeRepresents the various types of interaction.
-
Constructor Summary
Constructors Constructor Description Interaction(GatewayDiscordClient gateway, discord4j.discordjson.json.InteractionData data)Constructs anInteractionwith an associatedGatewayDiscordClientand Discord data.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description SnowflakegetApplicationId()Gets the id of the application this interaction is for.Mono<MessageChannel>getChannel()Gets the channel it was sent from.SnowflakegetChannelId()Gets the channel id it was sent from.GatewayDiscordClientgetClient()Returns theGatewayDiscordClientthat created this object.Optional<ApplicationCommandInteraction>getCommandInteraction()Gets the command data payload.discord4j.discordjson.json.InteractionDatagetData()Mono<Guild>getGuild()Gets the guild it was sent from, if invoked in a guild.Optional<Snowflake>getGuildId()Gets the guild id it was sent from, if invoked in a guild.Optional<String>getGuildLocale()Gets the guild's locale if the interaction was invoked from a guild.SnowflakegetId()Gets the id of the interaction.Optional<Member>getMember()Gets the invoking member, if invoked in a guild.Optional<Message>getMessage()Gets the message associated with the interaction.Optional<Snowflake>getMessageId()Gets the ID of the message associated with the interaction.StringgetToken()Gets the continuation token for responding to the interaction.Interaction.TypegetType()Gets the type of interaction.UsergetUser()Gets the invoking user.StringgetUserLocale()Gets the invoking user's client locale.
-
-
-
Constructor Detail
-
Interaction
public Interaction(GatewayDiscordClient gateway, discord4j.discordjson.json.InteractionData data)
Constructs anInteractionwith an associatedGatewayDiscordClientand Discord data.- Parameters:
gateway- TheGatewayDiscordClientassociated to this object, must be non-null.data- The raw data as represented by Discord, must be non-null.
-
-
Method Detail
-
getData
public discord4j.discordjson.json.InteractionData getData()
-
getId
public Snowflake getId()
Gets the id of the interaction.- Returns:
- The id of the interaction.
-
getApplicationId
public Snowflake getApplicationId()
Gets the id of the application this interaction is for.- Returns:
- The id of the application this interaction is for.
-
getType
public Interaction.Type getType()
Gets the type of interaction.- Returns:
- The type of interaction.
-
getCommandInteraction
public Optional<ApplicationCommandInteraction> getCommandInteraction()
Gets the command data payload.- Returns:
- The command data payload.
-
getGuildId
public Optional<Snowflake> getGuildId()
Gets the guild id it was sent from, if invoked in a guild.- Returns:
- The guild id it was sent from, if invoked in a guild.
-
getGuild
public Mono<Guild> getGuild()
Gets the guild it was sent from, if invoked in a guild.- Returns:
- The guild it was sent from, if invoked in a guild.
-
getChannelId
public Snowflake getChannelId()
Gets the channel id it was sent from.- Returns:
- The channel id it was sent from.
-
getChannel
public Mono<MessageChannel> getChannel()
Gets the channel it was sent from.- Returns:
- The channel it was sent from.
-
getMember
public Optional<Member> getMember()
Gets the invoking member, if invoked in a guild.- Returns:
- The invoking member, if invoked in a guild.
-
getUser
public User getUser()
Gets the invoking user. The user data is extracted from the member if invoked in a guild.- Returns:
- The invoking user. The user data is extracted from the member if invoked in a guild.
-
getToken
public String getToken()
Gets the continuation token for responding to the interaction.- Returns:
- The continuation token for responding to the interaction.
-
getMessage
public Optional<Message> getMessage()
Gets the message associated with the interaction.- Returns:
- The message associated with the interaction.
-
getMessageId
public Optional<Snowflake> getMessageId()
Gets the ID of the message associated with the interaction.- Returns:
- The message associated with the interaction.
-
getUserLocale
public String getUserLocale()
Gets the invoking user's client locale.
This is not present onPINGinteractions and will therefore default toen-US- Returns:
- The invoking user's client locale.
- See Also:
- Discord Locales
-
getGuildLocale
public Optional<String> getGuildLocale()
Gets the guild's locale if the interaction was invoked from a guild. Defaults toen-USfor non-community guilds.
This is not present onPINGinteractions- Returns:
- The locale of the guild where the interaction was invoked, otherwise
Optional.empty() - See Also:
- Discord Locales
-
getClient
public GatewayDiscordClient getClient()
Description copied from interface:DiscordObjectReturns theGatewayDiscordClientthat created this object. Methods in it are exclusively based on the entity cache orStorein use. Refer to callinggetClient().rest()to access aDiscordClientthat is capable of requesting entities directly from the REST API.- Specified by:
getClientin interfaceDiscordObject- Returns:
- The
GatewayDiscordClientassociated to this object.
-
-