DiscordのサーバートップにあるBOTの投稿したメッセージにリアクションをしたら役職を追加する機能を実装しています。
追加したらの部分はできたのですが、BOTが稼働してなかったときのリアクションを検知するため、BOT起動時にリアクションの内訳を確認する機能を追加したいです。
下記の記事を参考に、MessageReactionまでは取得できたのですが、forEachを回してもBOTしか表示されません。
discord.jsでメッセージにリアクションをしているユーザーを取得できない
実行しているのは下記コードです。
javascript
1 roleSettingMessage = await client.channels.cache.get('????????????????').messages.fetch('????????????????'); 2 const reactionCache = await roleSettingMessage.reactions.cache 3 4 for(let name in rolemoji){ 5 const messageReactions = await reactionCache.find(emoji => emoji._emoji.name === name) 6 if(messageReactions != null) { 7 const reactionUsers = messageReactions.users.cache 8 reactionUsers.forEach(function(data){ 9 console.log(data.username); 10 }) 11 } 12 }
出力結果は以下の通りです、最後のcountが4になっていることから、BOT含め4人のユーザーがリアクションしているのは間違いないと思うのですが…
<ref *2> MessageReaction { message: <ref *1> Message { channelId: '????????????????', guildId: '????????????????', id: '????????????????', createdTimestamp: ????????????, type: 'DEFAULT', system: false, content: '[BOT MESSAGE]', author: ClientUser { id: '????????????????', bot: true, system: false, flags: [UserFlags], username: '[BOT NAME'], discriminator: '????', avatar: null, banner: undefined, accentColor: undefined, verified: true, mfaEnabled: false }, pinned: false, tts: false, nonce: null, embeds: [], components: [], attachments: Collection(0) [Map] {}, stickers: Collection(0) [Map] {}, editedTimestamp: null, reactions: ReactionManager { message: [Circular *1] }, mentions: MessageMentions { everyone: false, users: Collection(0) [Map] {}, roles: Collection(0) [Map] {}, _members: null, _channels: null, crosspostedChannels: Collection(0) [Map] {}, repliedUser: null }, webhookId: null, groupActivityApplication: null, applicationId: null, activity: null, flags: MessageFlags { bitfield: 0 }, reference: null, interaction: null }, me: true, users: ReactionUserManager { reaction: [Circular *2] }, _emoji: ReactionEmoji { animated: null, name: '????', id: '????????????????', reaction: [Circular *2] }, count: 4 }
あなたの回答
tips
プレビュー