JDA Discord - How to get all names of Users who reacted to a bot's message in an array

1.5k Views Asked by At

I am trying to code a giveaway bot. I am having problems getting all Usernames of Users who reacted to the Giveaway Message that have been sent by the bot and store them in a Array of Type String.

2

There are 2 best solutions below

0
On BEST ANSWER

You can get the Message object of the message by getting the history of the channel its in and then get the message by id from the history.

The Message object has a getReactions method that returns a list of all reactions on a message, you can then iterate through the reactions and in turn then iterate thru all the users that reacted on the given reaction and save the name/id of each user who reacted into an array or list or data structure of your choice.

0
On
List<MessageReaction> reactionsList = event.event.getMessage().getReactions();

// List of users that reacted to every possible emote.
for (int i = 0; i < reactionsList.size(); i++)
{
    List<User> users = reactionsList.get(i).retrieveUsers().complete();
}