From 460ac7dfe28bf92deaef4c457964677a412ecd8a Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Mon, 8 May 2023 18:12:31 +0100 Subject: [PATCH 1/5] chore: Add repository directory (#9552) chore: add repository directory --- packages/create-discord-bot/package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/create-discord-bot/package.json b/packages/create-discord-bot/package.json index a1a929cc6031..c68205516804 100644 --- a/packages/create-discord-bot/package.json +++ b/packages/create-discord-bot/package.json @@ -37,7 +37,8 @@ ], "repository": { "type": "git", - "url": "git+https://github.com/discordjs/discord.js.git" + "url": "git+https://github.com/discordjs/discord.js.git", + "directory": "packages/create-discord-bot" }, "bugs": { "url": "https://github.com/discordjs/discord.js/issues" From 0c175c02e968fd9344f90490f909208496305ed1 Mon Sep 17 00:00:00 2001 From: brynpttrsn Date: Tue, 9 May 2023 10:02:52 -0400 Subject: [PATCH 2/5] fix(website): package and version button formatting (#9556) * fix for djs package button and removed redundant divs * version arrow formatting * formatting --- .../src/app/docs/packages/[package]/page.tsx | 2 +- apps/website/src/app/docs/packages/page.tsx | 45 ++++++++----------- 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/apps/website/src/app/docs/packages/[package]/page.tsx b/apps/website/src/app/docs/packages/[package]/page.tsx index 19928b6a6502..51436a329940 100644 --- a/apps/website/src/app/docs/packages/[package]/page.tsx +++ b/apps/website/src/app/docs/packages/[package]/page.tsx @@ -36,7 +36,7 @@ export default async function Page({ params }: { params: { package: string } }) href={`/docs/packages/${params.package}/${version}`} key={`${version}-${idx}`} > -
+

{version}

diff --git a/apps/website/src/app/docs/packages/page.tsx b/apps/website/src/app/docs/packages/page.tsx index ca72a67e69af..d88b18a67af5 100644 --- a/apps/website/src/app/docs/packages/page.tsx +++ b/apps/website/src/app/docs/packages/page.tsx @@ -13,16 +13,11 @@ export default function Page() {

Select a package:

- +
-
-
- -

discord.js

-
+
+ +

discord.js

@@ -34,31 +29,27 @@ export default function Page() { key={`${pkg}-${idx}`} >
-
-
- -

{pkg}

-
- {/* -
- Select version -
- */} +
+ +

{pkg}

+ {/* +
+ Select version +
+ */}
))}
-
-
- -

discord-api-types

-
+
+ +

discord-api-types

From 7b617bd22ecb4c009bdb0d807032134b51f6a855 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Tue, 9 May 2023 20:49:07 +0100 Subject: [PATCH 3/5] feat: Create discord-api-types documentation component (#9555) feat: add discord-api-types link component Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- .../src/components/DiscordAPITypesLink.tsx | 91 +++++++++++++++++++ apps/guide/src/components/Mdx.tsx | 2 + .../04-popular-topics/02-audit-logs.mdx | 2 +- .../05-additional-info/03-updating-to-v14.mdx | 8 +- apps/guide/src/util/constants.ts | 12 +++ 5 files changed, 110 insertions(+), 5 deletions(-) create mode 100644 apps/guide/src/components/DiscordAPITypesLink.tsx diff --git a/apps/guide/src/components/DiscordAPITypesLink.tsx b/apps/guide/src/components/DiscordAPITypesLink.tsx new file mode 100644 index 000000000000..4b7f6f182289 --- /dev/null +++ b/apps/guide/src/components/DiscordAPITypesLink.tsx @@ -0,0 +1,91 @@ +import { FiExternalLink } from '@react-icons/all-files/fi/FiExternalLink'; +import type { PropsWithChildren } from 'react'; +import { + BASE_URL_DISCORD_API_TYPES, + DISCORD_API_TYPES_VERSION, + DISCORD_API_TYPES_VOICE_VERSION, +} from '~/util/constants'; + +interface DiscordAPITypesLinkOptions { + /** + * The initial documentation enum, interface, function etc. + * + * @example `'RESTJSONErrorCodes'` + */ + parent?: string; + /** + * The scope of where this link lives. + * + * @remarks API does not have a scope. + */ + scope?: 'gateway' | 'globals' | 'payloads' | 'rest' | 'rpc' | 'utils' | 'voice'; + /** + * The symbol belonging to the parent. + * + * @example '`MaximumNumberOfGuildsReached'` + */ + symbol?: string; + /** + * The type of the {@link DiscordAPITypesLinkOptions.parent}. + * + * @example `'enum'` + * @example `'interface'` + */ + type?: string; +} + +export function DiscordAPITypesLink({ + parent, + scope, + symbol, + type, + children, +}: PropsWithChildren) { + let url = BASE_URL_DISCORD_API_TYPES; + let text = 'discord-api-types'; + + if (type || parent) { + url += `/api/discord-api-types`; + + switch (scope) { + case 'globals': + url += `-${scope}`; + break; + case 'gateway': + case 'payloads': + case 'rest': + url += `-${scope}/common`; + break; + case 'rpc': + case 'utils': + url += `-${scope}/${DISCORD_API_TYPES_VERSION}`; + break; + case 'voice': + url += `-${scope}/${DISCORD_API_TYPES_VOICE_VERSION}`; + break; + default: + url += `-${DISCORD_API_TYPES_VERSION}`; + } + + if (type) { + url += `/${type}/${parent}`; + if (symbol) url += `#${symbol}`; + } else { + url += `#${parent}`; + } + + text = `${parent}${symbol ? `#${symbol}` : ''}${type?.toUpperCase() === 'FUNCTION' ? '()' : ''}`; + } + + return ( +
+ {children ?? text} + + + ); +} diff --git a/apps/guide/src/components/Mdx.tsx b/apps/guide/src/components/Mdx.tsx index deb23121f1e5..05f0f89f56a1 100644 --- a/apps/guide/src/components/Mdx.tsx +++ b/apps/guide/src/components/Mdx.tsx @@ -2,6 +2,7 @@ import { Alert, Section, DiscordMessages, DiscordMessage, DiscordMessageEmbed } from '@discordjs/ui'; import { useMDXComponent } from 'next-contentlayer/hooks'; +import { DiscordAPITypesLink } from './DiscordAPITypesLink'; import { H1 } from './H1'; import { H2 } from './H2'; import { H3 } from './H3'; @@ -20,6 +21,7 @@ export function Mdx({ code }: { code: string }) { DiscordMessages, DiscordMessage, DiscordMessageEmbed, + DiscordAPITypesLink, DocsLink, ResultingCode, h1: H1, diff --git a/apps/guide/src/content/04-popular-topics/02-audit-logs.mdx b/apps/guide/src/content/04-popular-topics/02-audit-logs.mdx index ffeef10c545f..44f4e9c644c4 100644 --- a/apps/guide/src/content/04-popular-topics/02-audit-logs.mdx +++ b/apps/guide/src/content/04-popular-topics/02-audit-logs.mdx @@ -162,4 +162,4 @@ client.on(Events.GuildAuditLogEntryCreate, async (auditLog) => { -If you want to check who banned a user, it's the same example as above except the _`action`_ should be _`AuditLogEvent.MemberBanAdd`_. You can check the rest of the types over at the [discord-api-types documentation](https://discord-api-types.dev/api/discord-api-types-v10/enum/AuditLogEvent). +If you want to check who banned a user, it's the same example as above except the _`action`_ should be . You can check the rest of the possible actions on this page. diff --git a/apps/guide/src/content/05-additional-info/03-updating-to-v14.mdx b/apps/guide/src/content/05-additional-info/03-updating-to-v14.mdx index 6c6d01172d5f..bc8aadb9f4d4 100644 --- a/apps/guide/src/content/05-additional-info/03-updating-to-v14.mdx +++ b/apps/guide/src/content/05-additional-info/03-updating-to-v14.mdx @@ -41,7 +41,7 @@ discord.js v14 makes the switch to Discord API v10! Any areas that used to accept a _`string`_ or _`number`_ type for an enum parameter will now only accept a _`number`_. -In addition, the old enums exported by discord.js v13 and lower are replaced with new enums from [discord-api-types](https://discord-api-types.dev/api/discord-api-types-v10). +In addition, the old enums exported by discord.js v13 and lower are replaced with new enums from . #### New enum differences @@ -121,7 +121,7 @@ Areas like _`Client`_ initialization, JSON slash commands and JSON message compo #### Channels -Some channel type guard methods that narrowed to one channel type have been removed. Instead compare the _`type`_ property against a [ChannelType](https://discord-api-types.dev/api/discord-api-types-v10/enum/ChannelType) enum member to narrow channels. +Some channel type guard methods that narrowed to one channel type have been removed. Instead compare the _`type`_ property against a enum member to narrow channels. @@ -361,7 +361,7 @@ _`IntegrationApplication#summary`_ has been removed as it is no longer supported ### Interaction -Whenever an interaction is replied to and one fetches the reply, it could possibly give an [APIMessage](https://discord-api-types.dev/api/discord-api-types-v10/interface/APIMessage) if the guild was not cached. However, interaction replies now always return a discord.js object with _`fetchReply`_ as _`true`_. +Whenever an interaction is replied to and one fetches the reply, it could possibly give an if the guild was not cached. However, interaction replies now always return a discord.js object with _`fetchReply`_ as _`true`_. The base interaction class is now . @@ -690,7 +690,7 @@ Added support for role connection metadata. A new event has been added which is emitted whenever an element is not collected by the collector. -Component collector options now use the [ComponentType](https://discord-api-types.dev/api/discord-api-types-v10/enum/ComponentType) enum values: +Component collector options now use the enum values: diff --git a/apps/guide/src/util/constants.ts b/apps/guide/src/util/constants.ts index dbba83df8e29..d2ee15d21901 100644 --- a/apps/guide/src/util/constants.ts +++ b/apps/guide/src/util/constants.ts @@ -2,6 +2,8 @@ export const BASE_URL = 'https://discord.js.org/docs/packages' as const; export const BASE_URL_LEGACY = 'https://old.discordjs.dev/#/docs/discord.js' as const; +export const BASE_URL_DISCORD_API_TYPES = 'https://discord-api-types.dev' as const; + export const DESCRIPTION = 'Imagine a guide... that explores the many possibilities for your discord.js bot.'; export const GITHUB_BASE_PAGES_PATH = 'https://github.com/discordjs/discord.js/tree/main/apps/guide/src/pages'; @@ -25,3 +27,13 @@ export const PACKAGES = [ * The stable version of discord.js. */ export const VERSION = '14.11.0' as const; + +/** + * The API version (for discord-api-types). This is prefixed with a "v". + */ +export const DISCORD_API_TYPES_VERSION = 'v10' as const; + +/** + * The voice API version (for discord-api-types). This is prefixed with a "v". + */ +export const DISCORD_API_TYPES_VOICE_VERSION = 'v4' as const; From 1edd01a7a494ee7604b81bc2a3ec25a55d957f92 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Wed, 10 May 2023 17:40:52 +0100 Subject: [PATCH 4/5] feat(client): Support more request member fields (#9475) feat(client): support more request member fields Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/core/src/client.ts | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/packages/core/src/client.ts b/packages/core/src/client.ts index a7c3b9c037a4..5c563f0eb955 100644 --- a/packages/core/src/client.ts +++ b/packages/core/src/client.ts @@ -7,7 +7,6 @@ import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter'; import { GatewayDispatchEvents, GatewayOpcodes, - type APIGuildMember, type GatewayAutoModerationActionExecutionDispatchData, type GatewayAutoModerationRuleCreateDispatchData, type GatewayAutoModerationRuleDeleteDispatchData, @@ -169,6 +168,13 @@ export interface ClientOptions { rest: REST; } +export interface RequestGuildMembersResult { + members: GatewayGuildMembersChunkDispatchData['members']; + nonce: NonNullable; + notFound: NonNullable; + presences: NonNullable; +} + export class Client extends AsyncEventEmitter { public readonly rest: REST; @@ -199,8 +205,10 @@ export class Client extends AsyncEventEmitter { const shardId = calculateShardId(options.guild_id, await this.gateway.getShardCount()); const nonce = options.nonce ?? DiscordSnowflake.generate().toString(); - const promise = new Promise((resolve, reject) => { - const guildMembers: APIGuildMember[] = []; + const promise = new Promise((resolve, reject) => { + const members: RequestGuildMembersResult['members'] = []; + const notFound: RequestGuildMembersResult['notFound'] = []; + const presences: RequestGuildMembersResult['presences'] = []; const timer = setTimeout(() => { reject(new Error('Request timed out')); @@ -211,11 +219,13 @@ export class Client extends AsyncEventEmitter { if (data.nonce !== nonce) return; - guildMembers.push(...data.members); + members.push(...data.members); + if ('presences' in data) presences.push(...data.presences); + if ('not_found' in data) notFound.push(...data.not_found); if (data.chunk_index >= data.chunk_count - 1) { this.off(GatewayDispatchEvents.GuildMembersChunk, handler); - resolve(guildMembers); + resolve({ members, nonce, notFound, presences }); } }; From a51c48e7435902cab7de0d4e16bc6fc8a448d747 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Thu, 11 May 2023 17:43:54 +0100 Subject: [PATCH 5/5] fix(webhooks): Remove incorrect properties in edit message code sample (#9562) fix(webhooks): remove incorrect properties in edit message code sample --- apps/guide/src/content/04-popular-topics/04-webhooks.mdx | 2 -- 1 file changed, 2 deletions(-) diff --git a/apps/guide/src/content/04-popular-topics/04-webhooks.mdx b/apps/guide/src/content/04-popular-topics/04-webhooks.mdx index cbaa5afc64e9..a5fb46c00ef7 100644 --- a/apps/guide/src/content/04-popular-topics/04-webhooks.mdx +++ b/apps/guide/src/content/04-popular-topics/04-webhooks.mdx @@ -208,8 +208,6 @@ You can use