Interface Interaction
-
- All Superinterfaces:
ISnowflake
- All Known Subinterfaces:
ButtonInteraction
,CommandAutoCompleteInteraction
,CommandInteraction
,CommandInteractionPayload
,ComponentInteraction
,ContextInteraction<T>
,IAutoCompleteCallback
,IDeferrableCallback
,IMessageEditCallback
,IReplyCallback
,MessageContextInteraction
,SelectMenuInteraction
,SlashCommandInteraction
,UserContextInteraction
- All Known Implementing Classes:
ButtonInteractionEvent
,CommandAutoCompleteInteractionEvent
,GenericAutoCompleteInteractionEvent
,GenericCommandInteractionEvent
,GenericComponentInteractionCreateEvent
,GenericContextInteractionEvent
,GenericInteractionCreateEvent
,MessageContextInteractionEvent
,SelectMenuInteractionEvent
,SlashCommandInteractionEvent
,UserContextInteractionEvent
public interface Interaction extends ISnowflake
Abstract representation for any kind of Discord interaction.
This includes things such asSlash-Commands
orButtons
.To properly handle an interaction you must acknowledge it. Each interaction has different callbacks which acknowledge the interaction. These are added by the individual
I...Callback
interfaces:IReplyCallback
Which supports direct message replies and deferred message replies viaIReplyCallback.reply(String)
andIReplyCallback.deferReply()
IMessageEditCallback
Which supports direct message edits and deferred message edits (or no-operation) viaIMessageEditCallback.editMessage(String)
andIMessageEditCallback.deferEdit()
IAutoCompleteCallback
Which supports choice suggestions for auto-complete interactions viaIAutoCompleteCallback.replyChoices(Command.Choice...)
Once the interaction is acknowledged, you can not reply with these methods again. If the interaction is a
deferrable
, you can useIDeferrableCallback.getHook()
to send additional messages or update the original reply. When usingIReplyCallback.deferReply()
the first message sent to theInteractionHook
will be identical to usingInteractionHook.editOriginal(String)
. You must decide whether your reply will be ephemeral or not before callingIReplyCallback.deferReply()
. So design your code flow with that in mind!You can only acknowledge an interaction once! Any additional calls to reply/deferReply will result in exceptions. You can use
isAcknowledged()
to check whether the interaction has been acknowledged already.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Channel
getChannel()
The channel this interaction happened in.default ChannelType
getChannelType()
TheChannelType
for the channel this interaction came from.Guild
getGuild()
TheGuild
this interaction happened in.default GuildChannel
getGuildChannel()
TheGuildChannel
this interaction happened in.default Locale
getGuildLocale()
Returns the preferred language of the Guild.JDA
getJDA()
Returns theJDA
instance of this interactionMember
getMember()
TheMember
who caused this interaction.default MessageChannel
getMessageChannel()
TheMessageChannel
this interaction happened in.default NewsChannel
getNewsChannel()
TheNewsChannel
this interaction happened in.default PrivateChannel
getPrivateChannel()
ThePrivateChannel
this interaction happened in.default TextChannel
getTextChannel()
TheTextChannel
this interaction happened in.default ThreadChannel
getThreadChannel()
TheThreadChannel
this interaction happened in.String
getToken()
The interaction token used for responding to an interaction.default InteractionType
getType()
TheInteractionType
for this interaction.int
getTypeRaw()
The raw interaction type.User
getUser()
TheUser
who caused this interaction.Locale
getUserLocale()
Returns the selected language of the invoking user.default VoiceChannel
getVoiceChannel()
TheVoiceChannel
this interaction happened in.boolean
isAcknowledged()
Whether this interaction has already been acknowledged.default boolean
isFromGuild()
Whether this interaction came from aGuild
.-
Methods inherited from interface net.dv8tion.jda.api.entities.ISnowflake
getId, getIdLong, getTimeCreated
-
-
-
-
Method Detail
-
getTypeRaw
int getTypeRaw()
The raw interaction type.
It is recommended to usegetType()
instead.- Returns:
- The raw interaction type
-
getType
@Nonnull default InteractionType getType()
TheInteractionType
for this interaction.- Returns:
- The
InteractionType
orInteractionType.UNKNOWN
-
getToken
@Nonnull String getToken()
The interaction token used for responding to an interaction.- Returns:
- The interaction token
-
getGuild
@Nullable Guild getGuild()
TheGuild
this interaction happened in.
This is null in direct messages.- Returns:
- The
Guild
or null
-
isFromGuild
default boolean isFromGuild()
- Returns:
- True, if this interaction happened in a guild
-
getChannelType
@Nonnull default ChannelType getChannelType()
TheChannelType
for the channel this interaction came from.
IfgetChannel()
is null, this returnsChannelType.UNKNOWN
.- Returns:
- The
ChannelType
-
getMember
@Nullable Member getMember()
TheMember
who caused this interaction.
This is null if the interaction is not from a guild.- Returns:
- The
Member
-
getChannel
@Nullable Channel getChannel()
The channel this interaction happened in.
This is currently never null, but might be nullable in the future.- Returns:
- The channel or null if this interaction is not from a channel context
-
isAcknowledged
boolean isAcknowledged()
Whether this interaction has already been acknowledged.
Each interaction can only be acknowledged once.- Returns:
- True, if this interaction has already been acknowledged
-
getGuildChannel
@Nonnull default GuildChannel getGuildChannel()
TheGuildChannel
this interaction happened in.
IfgetChannelType()
is not a guild type, this throwsIllegalStateException
!- Returns:
- The
GuildChannel
- Throws:
IllegalStateException
- IfgetChannel()
is not a guild channel
-
getMessageChannel
@Nonnull default MessageChannel getMessageChannel()
TheMessageChannel
this interaction happened in.
IfgetChannelType()
is not a message channel type, this throwsIllegalStateException
!- Returns:
- The
MessageChannel
- Throws:
IllegalStateException
- IfgetChannel()
is not a message channel
-
getTextChannel
@Nonnull default TextChannel getTextChannel()
TheTextChannel
this interaction happened in.
IfgetChannelType()
is notChannelType.TEXT
, this throwsIllegalStateException
!- Returns:
- The
TextChannel
- Throws:
IllegalStateException
- IfgetChannel()
is not a text channel
-
getNewsChannel
@Nonnull default NewsChannel getNewsChannel()
TheNewsChannel
this interaction happened in.
IfgetChannelType()
is notChannelType.NEWS
, this throwsIllegalStateException
!- Returns:
- The
NewsChannel
- Throws:
IllegalStateException
- IfgetChannel()
is not a news channel
-
getVoiceChannel
@Nonnull default VoiceChannel getVoiceChannel()
TheVoiceChannel
this interaction happened in.
IfgetChannelType()
is notChannelType.VOICE
, this throwsIllegalStateException
!- Returns:
- The
VoiceChannel
- Throws:
IllegalStateException
- IfgetChannel()
is not a voice channel
-
getPrivateChannel
@Nonnull default PrivateChannel getPrivateChannel()
ThePrivateChannel
this interaction happened in.
IfgetChannelType()
is notChannelType.PRIVATE
, this throwsIllegalStateException
!- Returns:
- The
PrivateChannel
- Throws:
IllegalStateException
- IfgetChannel()
is not a private channel
-
getThreadChannel
@Nonnull default ThreadChannel getThreadChannel()
TheThreadChannel
this interaction happened in.
IfgetChannelType()
is notChannelType.isThread()
, this throwsIllegalStateException
!- Returns:
- The
ThreadChannel
- Throws:
IllegalStateException
- IfgetChannel()
is not a thread channel
-
getUserLocale
@Nonnull Locale getUserLocale()
Returns the selected language of the invoking user.- Returns:
- The language of the invoking user
-
getGuildLocale
@Nonnull default Locale getGuildLocale()
Returns the preferred language of the Guild.
This is identical togetGuild().getLocale()
.- Returns:
- The preferred language of the Guild
- Throws:
IllegalStateException
- If this interaction is not from a guild. (SeeisFromGuild()
)
-
-