-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
MentionableSelectMenuInteraction.js
71 lines (59 loc) · 1.87 KB
/
MentionableSelectMenuInteraction.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
'use strict';
const { Collection } = require('@discordjs/collection');
const MessageComponentInteraction = require('./MessageComponentInteraction');
const Events = require('../util/Events');
/**
* Represents a {@link ComponentType.MentionableSelect} select menu interaction.
* @extends {MessageComponentInteraction}
*/
class MentionableSelectMenuInteraction extends MessageComponentInteraction {
constructor(client, data) {
super(client, data);
const { resolved, values } = data.data;
const { members, users, roles } = resolved ?? {};
/**
* An array of the selected user and role ids
* @type {Snowflake[]}
*/
this.values = values ?? [];
/**
* Collection of the selected users
* @type {Collection<Snowflake, User>}
*/
this.users = new Collection();
/**
* Collection of the selected users
* @type {Collection<Snowflake, GuildMember|APIGuildMember>}
*/
this.members = new Collection();
/**
* Collection of the selected roles
* @type {Collection<Snowflake, Role|APIRole>}
*/
this.roles = new Collection();
if (members) {
for (const [id, member] of Object.entries(members)) {
const user = users[id];
if (!user) {
this.client.emit(
Events.Debug,
`[MentionableSelectMenuInteraction] Received a member without a user, skipping ${id}`,
);
continue;
}
this.members.set(id, this.guild?.members._add({ user, ...member }) ?? { user, ...member });
}
}
if (users) {
for (const user of Object.values(users)) {
this.users.set(user.id, this.client.users._add(user));
}
}
if (roles) {
for (const role of Object.values(roles)) {
this.roles.set(role.id, this.guild?.roles._add(role) ?? role);
}
}
}
}
module.exports = MentionableSelectMenuInteraction;