Skip to content

Commit

Permalink
fix: Prevent crash on no select menu option (#8881)
Browse files Browse the repository at this point in the history
* fix: no crash on no option

* refactor: consistency in ??

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
Jiralite and kodiakhq[bot] committed Dec 1, 2022
1 parent f13ff5c commit 11d195d
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 21 deletions.
Expand Up @@ -10,19 +10,21 @@ const MessageComponentInteraction = require('./MessageComponentInteraction');
class ChannelSelectMenuInteraction extends MessageComponentInteraction {
constructor(client, data) {
super(client, data);
const { resolved, values } = data.data;

/**
* An array of the selected channel ids
* @type {Snowflake[]}
*/
this.values = data.data.values ?? [];
this.values = values ?? [];

/**
* Collection of the selected channels
* @type {Collection<Snowflake, Channel|APIChannel>}
*/
this.channels = new Collection();
for (const channel of Object.values(data.data.resolved.channels)) {

for (const channel of Object.values(resolved?.channels ?? {})) {
this.channels.set(channel.id, this.client.channels._add(channel, this.guild) ?? channel);
}
}
Expand Down
Expand Up @@ -11,14 +11,14 @@ const Events = require('../util/Events');
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 = data.data.values ?? [];

const { members, users, roles } = data.data.resolved ?? {};
this.values = values ?? [];

/**
* Collection of the selected users
Expand Down
Expand Up @@ -10,19 +10,21 @@ const MessageComponentInteraction = require('./MessageComponentInteraction');
class RoleSelectMenuInteraction extends MessageComponentInteraction {
constructor(client, data) {
super(client, data);
const { resolved, values } = data.data;

/**
* An array of the selected role ids
* @type {Snowflake[]}
*/
this.values = data.data.values ?? [];
this.values = values ?? [];

/**
* Collection of the selected roles
* @type {Collection<Snowflake, Role|APIRole>}
*/
this.roles = new Collection();
for (const role of Object.values(data.data.resolved.roles)) {

for (const role of Object.values(resolved?.roles ?? {})) {
this.roles.set(role.id, this.guild?.roles._add(role) ?? role);
}
}
Expand Down
24 changes: 10 additions & 14 deletions packages/discord.js/src/structures/UserSelectMenuInteraction.js
Expand Up @@ -11,12 +11,13 @@ const Events = require('../util/Events');
class UserSelectMenuInteraction extends MessageComponentInteraction {
constructor(client, data) {
super(client, data);
const { resolved, values } = data.data;

/**
* An array of the selected user ids
* @type {Snowflake[]}
*/
this.values = data.data.values ?? [];
this.values = values ?? [];

/**
* Collection of the selected users
Expand All @@ -30,24 +31,19 @@ class UserSelectMenuInteraction extends MessageComponentInteraction {
*/
this.members = new Collection();

for (const user of Object.values(data.data.resolved.users)) {
for (const user of Object.values(resolved?.users ?? {})) {
this.users.set(user.id, this.client.users._add(user));
}

if (data.data.resolved.members) {
for (const [id, member] of Object.entries(data.data.resolved.members)) {
const user = data.data.resolved.users[id];
if (!user) {
this.client.emit(
Events.Debug,
`[UserSelectMenuInteraction] Received a member without a user, skipping ${id}`,
);
for (const [id, member] of Object.entries(resolved?.members ?? {})) {
const user = resolved.users[id];

continue;
}

this.members.set(id, this.guild?.members._add({ user, ...member }) ?? { user, ...member });
if (!user) {
this.client.emit(Events.Debug, `[UserSelectMenuInteraction] Received a member without a user, skipping ${id}`);
continue;
}

this.members.set(id, this.guild?.members._add({ user, ...member }) ?? { user, ...member });
}
}
}
Expand Down

0 comments on commit 11d195d

Please sign in to comment.