Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getUser() method to Interaction events #1217

Merged
merged 4 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import discord4j.core.event.domain.Event;
import discord4j.core.object.command.Interaction;
import discord4j.core.object.entity.Message;
import discord4j.core.object.entity.User;
import discord4j.discordjson.json.*;
import discord4j.discordjson.possible.Possible;
import discord4j.gateway.ShardInfo;
Expand Down Expand Up @@ -73,6 +74,16 @@ public Interaction getInteraction() {
return interaction;
}

/**
* Gets the {@link discord4j.core.object.entity.User} associated with the event.
Doc94 marked this conversation as resolved.
Show resolved Hide resolved
* The User is retrieved from the {@link #getInteraction} method.
*
* @return The {@link discord4j.core.object.entity.User} associated with the event.
*/
public User getUser() {
return interaction.getUser();
}

@Deprecated
protected Mono<Void> createInteractionResponse(InteractionResponseType responseType,
@Nullable InteractionApplicationCommandCallbackData data) {
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/java/discord4j/core/ExampleInteractions.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static void main(String[] args) {

Publisher<?> onSelect = client.on(SelectMenuInteractionEvent.class, event -> {
if (REPLY_MODE_SELECT.equals(event.getCustomId())) {
Snowflake user = event.getInteraction().getUser().getId();
Snowflake user = event.getUser().getId();
String selected = event.getValues().get(0);
String previous = modeByUser.put(user, selected);
if (previous == null) {
Expand All @@ -134,7 +134,7 @@ public static void main(String[] args) {
// create a listener that handles the button click
Publisher<?> onButton = client.on(ButtonInteractionEvent.class, event -> {
if (ACTION_BUTTON.equals(event.getCustomId())) {
Snowflake user = event.getInteraction().getUser().getId();
Snowflake user = event.getUser().getId();
String mode = modeByUser.getOrDefault(user, DEFER_REPLY);
switch (mode) {
case DEFER_REPLY:
Expand Down
Loading