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 class
Interaction.Type
Represents the various types of interaction.
-
Constructor Summary
Constructors Constructor Description Interaction(GatewayDiscordClient gateway, discord4j.discordjson.json.InteractionData data)
Constructs anInteraction
with an associatedGatewayDiscordClient
and Discord data.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Snowflake
getApplicationId()
Gets the id of the application this interaction is for.Mono<MessageChannel>
getChannel()
Gets the channel it was sent from.Snowflake
getChannelId()
Gets the channel id it was sent from.GatewayDiscordClient
getClient()
Returns theGatewayDiscordClient
that created this object.Optional<ApplicationCommandInteraction>
getCommandInteraction()
Gets the command data payload.discord4j.discordjson.json.InteractionData
getData()
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.Snowflake
getId()
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.String
getToken()
Gets the continuation token for responding to the interaction.Interaction.Type
getType()
Gets the type of interaction.User
getUser()
Gets the invoking user.String
getUserLocale()
Gets the invoking user's client locale.
-
-
-
Constructor Detail
-
Interaction
public Interaction(GatewayDiscordClient gateway, discord4j.discordjson.json.InteractionData data)
Constructs anInteraction
with an associatedGatewayDiscordClient
and Discord data.- Parameters:
gateway
- TheGatewayDiscordClient
associated 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 onPING
interactions 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-US
for non-community guilds.
This is not present onPING
interactions- 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:DiscordObject
Returns theGatewayDiscordClient
that created this object. Methods in it are exclusively based on the entity cache orStore
in use. Refer to callinggetClient().rest()
to access aDiscordClient
that is capable of requesting entities directly from the REST API.- Specified by:
getClient
in interfaceDiscordObject
- Returns:
- The
GatewayDiscordClient
associated to this object.
-
-