Class ButtonClickEvent
- java.lang.Object
-
- net.dv8tion.jda.api.events.Event
-
- net.dv8tion.jda.api.events.interaction.GenericInteractionCreateEvent
-
- net.dv8tion.jda.api.events.interaction.ButtonClickEvent
-
- All Implemented Interfaces:
ISnowflake
,GenericEvent
,ButtonInteraction
,ComponentInteraction
,Interaction
public class ButtonClickEvent extends GenericInteractionCreateEvent implements ButtonInteraction
Indicates that a customButton
on one of the bots messages was clicked by a user.This fires when a user clicks one of the custom buttons attached to a bot or webhook message.
Keep in mind that users can use your webhooks to spoof components!Requirements
To receive these events, you must unset the Interactions Endpoint URL in your application dashboard. You can simply remove the URL for this endpoint in your settings at the Discord Developers Portal.
-
-
Constructor Summary
Constructors Constructor Description ButtonClickEvent(JDA api, long responseNumber, ButtonInteraction interaction)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description UpdateInteractionAction
deferEdit()
No-op acknowledgement of this interaction.Button
getButton()
TheButton
this interaction belongs to.MessageChannel
getChannel()
The channel this interaction happened in.String
getComponentId()
The custom component Id provided to the component when it was originally created.Component.Type
getComponentType()
TheComponent.Type
ButtonInteraction
getInteraction()
TheInteraction
instance.Message
getMessage()
TheMessage
instance.long
getMessageIdLong()
The id of the message.-
Methods inherited from class net.dv8tion.jda.api.events.interaction.GenericInteractionCreateEvent
deferReply, getGuild, getHook, getIdLong, getMember, getToken, getTypeRaw, getUser, isAcknowledged
-
Methods inherited from class net.dv8tion.jda.api.events.Event
getJDA, getResponseNumber
-
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.dv8tion.jda.api.interactions.components.ButtonInteraction
editButton, getComponent
-
Methods inherited from interface net.dv8tion.jda.api.interactions.components.ComponentInteraction
editComponents, editComponents, editMessage, editMessage, editMessageEmbeds, editMessageEmbeds, editMessageFormat, getMessageId
-
Methods inherited from interface net.dv8tion.jda.api.interactions.Interaction
deferReply, deferReply, getChannelType, getGuild, getGuildChannel, getHook, getMember, getMessageChannel, getPrivateChannel, getTextChannel, getToken, getType, getTypeRaw, getUser, getVoiceChannel, isAcknowledged, isFromGuild, reply, reply, replyEmbeds, replyEmbeds, replyFormat
-
Methods inherited from interface net.dv8tion.jda.api.entities.ISnowflake
getId, getIdLong, getTimeCreated
-
-
-
-
Constructor Detail
-
ButtonClickEvent
public ButtonClickEvent(@Nonnull JDA api, long responseNumber, @Nonnull ButtonInteraction interaction)
-
-
Method Detail
-
getChannel
@Nonnull public MessageChannel getChannel()
Description copied from interface:Interaction
The channel this interaction happened in.
This is currently never null, but might be nullable in the future.- Specified by:
getChannel
in interfaceComponentInteraction
- Specified by:
getChannel
in interfaceInteraction
- Overrides:
getChannel
in classGenericInteractionCreateEvent
- Returns:
- The channel or null if this interaction is not from a channel context
-
deferEdit
@Nonnull public UpdateInteractionAction deferEdit()
Description copied from interface:ComponentInteraction
No-op acknowledgement of this interaction.
This tells discord you intend to update the message that the triggering component is a part of using theInteractionHook
instead of sending a reply message. You are not required to actually update the message, this will simply acknowledge that you accepted the interaction.You only have 3 seconds to acknowledge an interaction!
When the acknowledgement is sent after the interaction expired, you will receiveErrorResponse.UNKNOWN_INTERACTION
.Use
ComponentInteraction.editMessage(String)
to edit it directly.- Specified by:
deferEdit
in interfaceComponentInteraction
- Returns:
UpdateInteractionAction
that can be used to update the message- See Also:
ComponentInteraction.editMessage(String)
-
getInteraction
@Nonnull public ButtonInteraction getInteraction()
Description copied from class:GenericInteractionCreateEvent
TheInteraction
instance.
Note that this event is a delegate which implements the same interface.- Overrides:
getInteraction
in classGenericInteractionCreateEvent
- Returns:
- The
Interaction
-
getComponentId
@Nonnull public String getComponentId()
Description copied from interface:ComponentInteraction
The custom component Id provided to the component when it was originally created.
This value should be used to determine what action to take in regards to this interaction.
This id does not have to be numerical.- Specified by:
getComponentId
in interfaceComponentInteraction
- Returns:
- The component ID
-
getMessage
@Nullable public Message getMessage()
Description copied from interface:ComponentInteraction
TheMessage
instance.
This is null on interactions for ephemeral messages.- Specified by:
getMessage
in interfaceComponentInteraction
- Returns:
- The
Message
, or null if this message is ephemeral
-
getMessageIdLong
public long getMessageIdLong()
Description copied from interface:ComponentInteraction
The id of the message.- Specified by:
getMessageIdLong
in interfaceComponentInteraction
- Returns:
- The message id
-
getComponentType
@Nonnull public Component.Type getComponentType()
Description copied from interface:ComponentInteraction
TheComponent.Type
- Specified by:
getComponentType
in interfaceComponentInteraction
- Returns:
- The
Component.Type
-
getButton
@Nullable public Button getButton()
Description copied from interface:ButtonInteraction
TheButton
this interaction belongs to.
This is null for ephemeral messages!- Specified by:
getButton
in interfaceButtonInteraction
- Returns:
- The
Button
- See Also:
ComponentInteraction.getComponentId()
-
-