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

huangapple go评论89阅读模式
英文:

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

问题

我正在尝试编写一个抽奖机器人。我遇到了问题,无法获取对机器人发送的抽奖消息做出反应的所有用户的用户名,并将它们存储在一个类型为StringArray中。

英文:

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.

答案1

得分: 1

你可以通过获取所在频道的历史记录并根据消息的ID从历史记录中获取消息的“Message”对象。

“Message”对象有一个“getReactions”方法,它返回消息上所有反应的列表,然后你可以遍历这些反应,然后再遍历给定反应上的所有用户,并将每个反应的用户名/ID保存到你选择的数组、列表或数据结构中。

英文:

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.

答案2

得分: 0

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();
}
英文:
List&lt;MessageReaction&gt; reactionsList = event.event.getMessage().getReactions();

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

huangapple
  • 本文由 发表于 2020年10月24日 04:17:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/64506765.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定