回答編集履歴
4
コード修正
answer
CHANGED
@@ -14,12 +14,15 @@
|
|
14
14
|
return ['????', '????'].includes(reaction.emoji.name);
|
15
15
|
};
|
16
16
|
|
17
|
-
|
17
|
+
message.awaitReactions({ filter })
|
18
|
+
.then(collected => {
|
18
|
-
// collectedはCollection<string, MessageReaction>
|
19
|
+
// collectedはCollection<string, MessageReaction>
|
19
|
-
// reaction.usersはReactionUserManager
|
20
|
+
// reaction.usersはReactionUserManager
|
20
|
-
// reaction.users.cacheはCollection<Snowflake, User>
|
21
|
+
// reaction.users.cacheはCollection<Snowflake, User>
|
21
|
-
// collected.map(...)だけだと[[User, User, ...], [User, ...], ...]となるためflattenする
|
22
|
+
// collected.map(...)だけだと[[User, User, ...], [User, ...], ...]となるためflattenする
|
22
|
-
const users = collected.map(reaction => reaction.users.cache.values()).flat();
|
23
|
+
const users = collected.map(reaction => reaction.users.cache.values()).flat();
|
24
|
+
/* ... */
|
25
|
+
});
|
23
26
|
```
|
24
27
|
|
25
28
|
上のコードは実際に試したわけではないので、雰囲気を感じていただければ。
|
3
リンクをまとめた
answer
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
`Message`オブジェクトが取得できているのであれば、`Message.awaitReactions()`を使えばいいのではないでしょうか。
|
2
2
|
|
3
|
-
[Reactions | Discord.js Guide](https://discordjs.guide/popular-topics/reactions.html#awaiting-reactions)
|
3
|
+
- [Reactions | Discord.js Guide](https://discordjs.guide/popular-topics/reactions.html#awaiting-reactions)
|
4
|
+
- [Message.awaitReactions - discord.js](https://discord.js.org/#/docs/main/stable/class/Message?scrollTo=awaitReactions)
|
4
5
|
|
5
6
|
`filter`で特定のリアクションのみ抽出するようにし、見つかったリアクションそれぞれのユーザをリストにまとめれば扱いやすいかと。
|
6
7
|
|
@@ -23,6 +24,4 @@
|
|
23
24
|
|
24
25
|
上のコードは実際に試したわけではないので、雰囲気を感じていただければ。
|
25
26
|
|
26
|
-
[Message.awaitReactions - discord.js](https://discord.js.org/#/docs/main/stable/class/Message?scrollTo=awaitReactions)
|
27
|
-
|
28
27
|
ご参考まで。
|
2
コード修正
answer
CHANGED
@@ -13,15 +13,12 @@
|
|
13
13
|
return ['????', '????'].includes(reaction.emoji.name);
|
14
14
|
};
|
15
15
|
|
16
|
-
message.awaitReactions({ filter })
|
16
|
+
const collected = await message.awaitReactions({ filter });
|
17
|
-
.then(collected => {
|
18
|
-
|
17
|
+
// collectedはCollection<string, MessageReaction>
|
19
|
-
|
18
|
+
// reaction.usersはReactionUserManager
|
20
|
-
|
19
|
+
// reaction.users.cacheはCollection<Snowflake, User>
|
21
|
-
|
20
|
+
// collected.map(...)だけだと[[User, User, ...], [User, ...], ...]となるためflattenする
|
22
|
-
|
21
|
+
const users = collected.map(reaction => reaction.users.cache.values()).flat();
|
23
|
-
})
|
24
|
-
.catch(e => /* エラー処理 */);
|
25
22
|
```
|
26
23
|
|
27
24
|
上のコードは実際に試したわけではないので、雰囲気を感じていただければ。
|
1
Message取得方法について追記
answer
CHANGED
@@ -4,7 +4,11 @@
|
|
4
4
|
|
5
5
|
`filter`で特定のリアクションのみ抽出するようにし、見つかったリアクションそれぞれのユーザをリストにまとめれば扱いやすいかと。
|
6
6
|
|
7
|
+
`Message`自体は`Channel.send()`の返値を使えばいいでしょう。
|
8
|
+
|
7
9
|
```js
|
10
|
+
const message = channel.send('メッセージ');
|
11
|
+
|
8
12
|
const filter = (reaction, _user) => {
|
9
13
|
return ['????', '????'].includes(reaction.emoji.name);
|
10
14
|
};
|