Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Interactions)!: member objects for uncached guilds #10195

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
8 changes: 4 additions & 4 deletions packages/discord.js/src/managers/GuildMemberRoleManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GuildMemberRoleManager extends DataManager {
*/
get cache() {
const everyone = this.guild.roles.everyone;
return this.guild.roles.cache.filter(role => this.member._roles.includes(role.id)).set(everyone.id, everyone);
return this.guild.roles.cache.filter(role => this.member.roleIds.includes(role.id)).set(everyone.id, everyone);
}

/**
Expand Down Expand Up @@ -133,7 +133,7 @@ class GuildMemberRoleManager extends DataManager {
await this.client.rest.put(Routes.guildMemberRole(this.guild.id, this.member.id, roleOrRoles), { reason });

const clone = this.member._clone();
clone._roles = [...this.cache.keys(), roleOrRoles];
clone.roleIds = [...this.cache.keys(), roleOrRoles];
return clone;
}
}
Expand Down Expand Up @@ -173,7 +173,7 @@ class GuildMemberRoleManager extends DataManager {

const clone = this.member._clone();
const newRoles = this.cache.filter(role => role.id !== roleOrRoles);
clone._roles = [...newRoles.keys()];
clone.roleIds = [...newRoles.keys()];
return clone;
}
}
Expand All @@ -200,7 +200,7 @@ class GuildMemberRoleManager extends DataManager {

clone() {
const clone = new this.constructor(this.member);
clone.member._roles = [...this.cache.keys()];
clone.member.roleIds = [...this.cache.keys()];
return clone;
}
}
Expand Down
7 changes: 5 additions & 2 deletions packages/discord.js/src/structures/BaseInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const { Collection } = require('@discordjs/collection');
const { DiscordSnowflake } = require('@sapphire/snowflake');
const { InteractionType, ApplicationCommandType, ComponentType } = require('discord-api-types/v10');
const Base = require('./Base');
const MinimalGuildMember = require('./MinimalGuildMember');
const { SelectMenuTypes } = require('../util/Constants');
const PermissionsBitField = require('../util/PermissionsBitField');

Expand Down Expand Up @@ -62,9 +63,11 @@ class BaseInteraction extends Base {

/**
* If this interaction was sent in a guild, the member which sent it
* @type {?(GuildMember|APIInteractionGuildMember)}
* @type {?(GuildMember|MinimalGuildMember)}
*/
this.member = data.member ? (this.guild?.members._add(data.member) ?? data.member) : null;
this.member = data.member
? (this.guild?.members._add(data.member) ?? new MinimalGuildMember(this.client, data.member, this.guildId))
: null;

/**
* The version
Expand Down
11 changes: 8 additions & 3 deletions packages/discord.js/src/structures/CommandInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const Attachment = require('./Attachment');
const BaseInteraction = require('./BaseInteraction');
const InteractionWebhook = require('./InteractionWebhook');
const MinimalGuildMember = require('./MinimalGuildMember');
const InteractionResponses = require('./interfaces/InteractionResponses');

/**
Expand Down Expand Up @@ -83,7 +84,7 @@ class CommandInteraction extends BaseInteraction {
* Represents the resolved data of a received command interaction.
* @typedef {Object} CommandInteractionResolvedData
* @property {Collection<Snowflake, User>} [users] The resolved users
* @property {Collection<Snowflake, GuildMember|APIGuildMember>} [members] The resolved guild members
* @property {Collection<Snowflake, GuildMember|MinimalGuildMember>} [members] The resolved guild members
* @property {Collection<Snowflake, Role|APIRole>} [roles] The resolved roles
* @property {Collection<Snowflake, BaseChannel|APIChannel>} [channels] The resolved channels
* @property {Collection<Snowflake, Message|APIMessage>} [messages] The resolved messages
Expand All @@ -102,7 +103,7 @@ class CommandInteraction extends BaseInteraction {
* @property {CommandInteractionOption[]} [options] Additional options if this option is a
* subcommand (group)
* @property {User} [user] The resolved user
* @property {GuildMember|APIGuildMember} [member] The resolved member
* @property {GuildMember|MinimalGuildMember} [member] The resolved member
* @property {GuildChannel|ThreadChannel|APIChannel} [channel] The resolved channel
* @property {Role|APIRole} [role] The resolved role
* @property {Attachment} [attachment] The resolved attachment
Expand All @@ -129,7 +130,11 @@ class CommandInteraction extends BaseInteraction {
if (user) result.user = this.client.users._add(user);

const member = resolved.members?.[option.value];
if (member) result.member = this.guild?.members._add({ user, ...member }) ?? member;
if (member) {
result.member =
this.guild?.members._add({ user, ...member }) ??
new MinimalGuildMember(this.client, { user, ...member }, this.guildId);
}

const channel = resolved.channels?.[option.value];
if (channel) result.channel = this.client.channels._add(channel, this.guild) ?? channel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class CommandInteractionOptionResolver {
/**
* Gets a member option.
* @param {string} name The name of the option.
* @returns {?(GuildMember|APIGuildMember)}
* @returns {?(GuildMember|MinimalGuildMember)}
* The value of the option, or null if the user is not present in the guild or the option is not set.
*/
getMember(name) {
Expand Down Expand Up @@ -258,7 +258,7 @@ class CommandInteractionOptionResolver {
* Gets a mentionable option.
* @param {string} name The name of the option.
* @param {boolean} [required=false] Whether to throw an error if the option is not found.
* @returns {?(User|GuildMember|APIGuildMember|Role|APIRole)}
* @returns {?(User|GuildMember|MinimalGuildMember|Role|APIRole)}
* The value of the option, or null if not set and not required.
*/
getMentionable(name, required = false) {
Expand Down
Loading
Loading