Skip to content

Commit

Permalink
Merge branch 'main' into fix/builders-rest-array-inconsistency
Browse files Browse the repository at this point in the history
  • Loading branch information
kodiakhq[bot] committed Mar 24, 2024
2 parents 52e847a + ddc927f commit 8dae47b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/discord.js/src/errors/Messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ const Messages = {
[DjsErrorCodes.ChannelNotCached]: 'Could not find the channel where this message came from in the cache!',
[DjsErrorCodes.StageChannelResolve]: 'Could not resolve channel to a stage channel.',
[DjsErrorCodes.GuildScheduledEventResolve]: 'Could not resolve the guild scheduled event.',
[DjsErrorCodes.FetchOwnerId]: "Couldn't resolve the guild ownerId to fetch the member.",
[DjsErrorCodes.FetchOwnerId]: type => `Couldn't resolve the ${type} ownerId to fetch the ${type} member.`,

[DjsErrorCodes.InvalidType]: (name, expected, an = false) => `Supplied ${name} is not a${an ? 'n' : ''} ${expected}.`,
[DjsErrorCodes.InvalidElement]: (type, name, elem) => `Supplied ${type} ${name} includes an invalid element: ${elem}`,
Expand Down
21 changes: 19 additions & 2 deletions packages/discord.js/src/structures/Embed.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,26 @@ class Embed {
*/
equals(other) {
if (other instanceof Embed) {
return isEqual(other.data, this.data);
return isEqual(this.data, other.data);
}
return isEqual(other, this.data);

return (
this.author?.iconURL === other.author?.icon_url &&
this.author?.name === other.author?.name &&
this.author?.url === other.author?.url &&
this.color === (other.color ?? null) &&
this.description === (other.description ?? null) &&
this.footer?.iconURL === other.footer?.icon_url &&
this.footer?.text === other.footer?.text &&
this.image?.url === other.image?.url &&
this.thumbnail?.url === other.thumbnail?.url &&
(this.timestamp && Date.parse(this.timestamp)) === (other.timestamp ? Date.parse(other.timestamp) : null) &&
this.title === (other.title ?? null) &&
this.url === (other.url ?? null) &&
this.video?.url === other.video?.url &&
isEqual(this.fields, other.fields?.map(field => ({ ...field, inline: field.inline ?? false })) ?? []) &&
isEqual(this.provider, other.provider ?? null)
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ class Guild extends AnonymousGuild {
*/
async fetchOwner(options) {
if (!this.ownerId) {
throw new DiscordjsError(ErrorCodes.FetchOwnerId);
throw new DiscordjsError(ErrorCodes.FetchOwnerId, 'guild');
}
const member = await this.members.fetch({ ...options, user: this.ownerId });
return member;
Expand Down
25 changes: 16 additions & 9 deletions packages/discord.js/src/structures/ThreadChannel.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
'use strict';

const { DiscordAPIError } = require('@discordjs/rest');
const { lazy } = require('@discordjs/util');
const { ChannelType, PermissionFlagsBits, Routes, ChannelFlags } = require('discord-api-types/v10');
const { RESTJSONErrorCodes, ChannelFlags, ChannelType, PermissionFlagsBits, Routes } = require('discord-api-types/v10');
const { BaseChannel } = require('./BaseChannel');
const getThreadOnlyChannel = lazy(() => require('./ThreadOnlyChannel'));
const TextBasedChannel = require('./interfaces/TextBasedChannel');
const { DiscordjsRangeError, ErrorCodes } = require('../errors');
const { DiscordjsError, DiscordjsRangeError, ErrorCodes } = require('../errors');
const GuildMessageManager = require('../managers/GuildMessageManager');
const ThreadMemberManager = require('../managers/ThreadMemberManager');
const ChannelFlagsBitField = require('../util/ChannelFlagsBitField');
Expand Down Expand Up @@ -293,15 +294,21 @@ class ThreadChannel extends BaseChannel {
* @param {BaseFetchOptions} [options] The options for fetching the member
* @returns {Promise<?ThreadMember>}
*/
async fetchOwner({ cache = true, force = false } = {}) {
if (!force) {
const existing = this.members.cache.get(this.ownerId);
if (existing) return existing;
async fetchOwner(options) {
if (!this.ownerId) {
throw new DiscordjsError(ErrorCodes.FetchOwnerId, 'thread');
}

// We cannot fetch a single thread member, as of this commit's date, Discord API responds with 405
const members = await this.members.fetch({ cache });
return members.get(this.ownerId) ?? null;
// TODO: Remove that catch in the next major version
const member = await this.members._fetchSingle({ ...options, user: this.ownerId }).catch(error => {
if (error instanceof DiscordAPIError && error.code === RESTJSONErrorCodes.UnknownMember) {
return null;
}

throw error;
});

return member;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,7 @@ export class ClientVoiceManager {
public adapters: Map<Snowflake, InternalDiscordGatewayAdapterLibraryMethods>;
}

export { Collection } from '@discordjs/collection';
export { Collection, ReadonlyCollection } from '@discordjs/collection';

export interface CollectorEventTypes<Key, Value, Extras extends unknown[] = []> {
collect: [Value, ...Extras];
Expand Down

0 comments on commit 8dae47b

Please sign in to comment.