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

Create a new pull request by comparing changes across two branches #248

Merged
merged 10 commits into from
Sep 11, 2023
1 change: 1 addition & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:
- 'main'
paths:
- 'packages/*/src/**'
- '!packages/create-discord-bot/**'
tags:
- '**'
workflow_dispatch:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ jobs:
- name: Publish package
run: |
pnpm --filter=${{ matrix.package }} run release --preid "dev.$(date +%s)-$(git rev-parse --short HEAD)"
pnpm --filter=${{ matrix.package }} publish --tag dev || true
pnpm --filter=${{ matrix.package }} publish --no-git-checks --tag dev || true
env:
NPM_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ yarn init
pnpm init; pnpm pkg set type="module"
```

```sh bun
bun init
```

</CH.Code>

This is the next command you'll be running. This command creates a _`package.json`_ file for you, which will keep track of the dependencies your project uses, as well as other info.
Expand All @@ -93,6 +97,10 @@ yarn add discord.js
pnpm add discord.js
```

```sh bun
bun add discord.js
```

</CH.Code>

And that's it! With all the necessities installed, you're almost ready to start coding your bot.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ yarn add dotenv
pnpm add dotenv
```

```sh bun
# Bun automatically reads .env files
```

</CH.Code>

<CH.Code lineNumbers={false} rows={7}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ yarn remove @discordjs/builders @discordjs/formatters @discordjs/rest discord-ap
pnpm remove @discordjs/builders @discordjs/formatters @discordjs/rest discord-api-types
```

```sh bun
bun remove @discordjs/builders @discordjs/formatters @discordjs/rest discord-api-types
```

</CH.Code>

## Breaking Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/builders/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@discordjs/formatters": "workspace:^",
"@discordjs/util": "workspace:^",
"@sapphire/shapeshift": "^3.9.2",
"discord-api-types": "0.37.54",
"discord-api-types": "0.37.56",
"fast-deep-equal": "^3.1.3",
"ts-mixer": "^6.0.3",
"tslib": "^2.6.2"
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
"@discordjs/ws": "workspace:^",
"@sapphire/snowflake": "^3.5.1",
"@vladfrangu/async_event_emitter": "^2.2.2",
"discord-api-types": "0.37.54"
"discord-api-types": "0.37.56"
},
"devDependencies": {
"@favware/cliff-jumper": "^2.1.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/api/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class ApplicationsAPI {
* Fetches the application associated with the requesting bot user.
*
* @see {@link https://discord.com/developers/docs/resources/application#get-current-application}
* @param options - The options for editing the application
* @param options - The options for fetching the application
*/
public async getCurrent({ signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.currentApplication(), { signal }) as Promise<RESTGetCurrentApplicationResult>;
Expand Down
9 changes: 8 additions & 1 deletion packages/create-discord-bot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,14 @@

## About

`npx create-discord-bot ./your/chosen/directory/`. It's as easy as that to create a simple Discord bot to begin your journey with the Discord API.
It's easy to create a simple Discord bot to begin your journey with the Discord API.

```sh
npm create discord-bot ./your/chosen/directory
yarn create discord-bot ./your/chosen/directory
pnpm create discord-bot ./your/chosen/directory
bunx create-discord-bot ./your/chosen/directory
```

## Links

Expand Down
4 changes: 4 additions & 0 deletions packages/create-discord-bot/src/helpers/packageManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export function resolvePackageManager(): PackageManager {
return 'pnpm';
}

if (npmConfigUserAgent.startsWith('bun')) {
return 'bun';
}

console.error(
picocolors.yellow(
`Detected an unsupported package manager (${npmConfigUserAgent}). Falling back to ${DEFAULT_PACKAGE_MANAGER}.`,
Expand Down
2 changes: 2 additions & 0 deletions packages/discord.js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ discord.js is a powerful [Node.js](https://nodejs.org) module that allows you to
npm install discord.js
yarn add discord.js
pnpm add discord.js
bun add discord.js
```

### Optional packages
Expand All @@ -52,6 +53,7 @@ Install discord.js:
npm install discord.js
yarn add discord.js
pnpm add discord.js
bun add discord.js
```

Register a slash command against the Discord API:
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"@discordjs/ws": "workspace:^",
"@sapphire/snowflake": "3.5.1",
"@types/ws": "8.5.5",
"discord-api-types": "0.37.54",
"discord-api-types": "0.37.56",
"fast-deep-equal": "3.1.3",
"lodash.snakecase": "4.1.1",
"tslib": "2.6.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/discord.js/src/structures/GuildMember.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,8 +425,8 @@ class GuildMember extends Base {

/**
* Times this guild member out.
* @param {number|null} timeout The time in milliseconds
* for the member's communication to be disabled until. Provide `null` to remove the timeout.
* @param {number|null} timeout The duration in milliseconds
* for the member's communication to be disabled. Provide `null` to remove the timeout.
* @param {string} [reason] The reason for this timeout.
* @returns {Promise<GuildMember>}
* @example
Expand Down
2 changes: 1 addition & 1 deletion packages/discord.js/src/util/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const { version } = require('../../package.json');
* the client will spawn {@link ClientOptions#shardCount} shards. If set to `auto`, it will fetch the
* recommended amount of shards from Discord and spawn that amount
* @property {number} [closeTimeout=5_000] The amount of time in milliseconds to wait for the close frame to be received
* from the WebSocket. Don't have this too high/low. Its best to have it between 2_000-6_000 ms.
* from the WebSocket. Don't have this too high/low. It's best to have it between 2_000-6_000 ms.
* @property {number} [shardCount=1] The total amount of shards used by all processes of this bot
* (e.g. recommended shard count, shard count of the ShardingManager)
* @property {CacheFactory} [makeCache] Function to create a cache.
Expand Down
2 changes: 2 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,8 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
private _eval(script: string): unknown;
private _validateOptions(options: ClientOptions): void;
private get _censoredToken(): string | null;
// This a technique used to brand the ready state. Or else we'll get `never` errors on typeguard checks.
private readonly _ready: Ready;

public application: If<Ready, ClientApplication>;
public channels: ChannelManager;
Expand Down
6 changes: 6 additions & 0 deletions packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,12 @@ const client: Client = new Client({
}),
});

if (client.isReady()) {
expectType<Client<true>>(client);
} else {
expectType<Client>(client);
}

const testGuildId = '222078108977594368'; // DJS
const testUserId = '987654321098765432'; // example id
const globalCommandId = '123456789012345678'; // example id
Expand Down
1 change: 1 addition & 0 deletions packages/formatters/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
npm install @discordjs/formatters
yarn add @discordjs/formatters
pnpm add @discordjs/formatters
bun add @discordjs/formatters
```

## Example usage
Expand Down
2 changes: 1 addition & 1 deletion packages/formatters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
"homepage": "https://discord.js.org",
"dependencies": {
"discord-api-types": "0.37.54"
"discord-api-types": "0.37.56"
},
"devDependencies": {
"@favware/cliff-jumper": "^2.1.1",
Expand Down
1 change: 1 addition & 0 deletions packages/next/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
npm install @discordjs/next
yarn add @discordjs/next
pnpm add @discordjs/next
bun add @discordjs/next
```

## Links
Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"@discordjs/rest": "workspace:^",
"@discordjs/util": "workspace:^",
"@discordjs/ws": "workspace:^",
"discord-api-types": "0.37.54"
"discord-api-types": "0.37.56"
},
"devDependencies": {
"@favware/cliff-jumper": "^2.1.1",
Expand Down
1 change: 1 addition & 0 deletions packages/proxy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
npm install @discordjs/proxy
yarn add @discordjs/proxy
pnpm add @discordjs/proxy
bun add @discordjs/proxy
```

## Links
Expand Down
2 changes: 2 additions & 0 deletions packages/rest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Note: native fetch (not recommended) is unavailable in this node version, either
npm install @discordjs/rest
yarn add @discordjs/rest
pnpm add @discordjs/rest
bun add @discordjs/rest
```

## Examples
Expand All @@ -41,6 +42,7 @@ Install all required dependencies:
npm install @discordjs/rest discord-api-types
yarn add @discordjs/rest discord-api-types
pnpm add @discordjs/rest discord-api-types
bun add @discordjs/rest discord-api-types
```

Send a basic message:
Expand Down
2 changes: 1 addition & 1 deletion packages/rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
"@sapphire/async-queue": "^1.5.0",
"@sapphire/snowflake": "^3.5.1",
"@vladfrangu/async_event_emitter": "^2.2.2",
"discord-api-types": "0.37.54",
"discord-api-types": "0.37.56",
"magic-bytes.js": "^1.0.15",
"tslib": "^2.6.2",
"undici": "5.23.0"
Expand Down
35 changes: 33 additions & 2 deletions packages/rest/src/lib/CDN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import {
type ImageSize,
type StickerExtension,
} from './utils/constants.js';
import { deprecationWarning } from './utils/utils.js';

let deprecationEmittedForEmoji = false;

/**
* The options used for image URLs
Expand Down Expand Up @@ -154,14 +157,42 @@ export class CDN {
return this.makeURL(`/discovery-splashes/${guildId}/${splashHash}`, options);
}

/**
* Generates an emoji's URL for an emoji.
*
* @param emojiId - The emoji id
* @param options - Optional options for the emoji
*/
public emoji(emojiId: string, options?: Readonly<BaseImageURLOptions>): string;

/**
* Generates an emoji's URL for an emoji.
*
* @param emojiId - The emoji id
* @param extension - The extension of the emoji
* @deprecated This overload is deprecated. Pass an object containing the extension instead.
*/
public emoji(emojiId: string, extension?: ImageExtension): string {
return this.makeURL(`/emojis/${emojiId}`, { extension });
// eslint-disable-next-line @typescript-eslint/unified-signatures
public emoji(emojiId: string, extension?: ImageExtension): string;

public emoji(emojiId: string, options?: ImageExtension | Readonly<BaseImageURLOptions>): string {
let resolvedOptions;

if (typeof options === 'string') {
if (!deprecationEmittedForEmoji) {
deprecationWarning(
'Passing a string for the second parameter of CDN#emoji() is deprecated. Use an object instead.',
);

deprecationEmittedForEmoji = true;
}

resolvedOptions = { extension: options };
} else {
resolvedOptions = options;
}

return this.makeURL(`/emojis/${emojiId}`, resolvedOptions);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/rest/src/lib/REST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export class REST extends AsyncEventEmitter<RestEventsMap> {
headers.Authorization = `${request.authPrefix ?? this.options.authPrefix} ${this.#token}`;
}

// If a reason was set, set it's appropriate header
// If a reason was set, set its appropriate header
if (request.reason?.length) {
headers['X-Audit-Log-Reason'] = encodeURIComponent(request.reason);
}
Expand Down
7 changes: 7 additions & 0 deletions packages/rest/src/lib/utils/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,10 @@ export const OverwrittenMimeTypes = {
} as const satisfies Readonly<Record<string, string>>;

export const BurstHandlerMajorIdKey = 'burst';

/**
* Prefix for deprecation warnings.
*
* @internal
*/
export const DEPRECATION_WARNING_PREFIX = 'DeprecationWarning' as const;
16 changes: 16 additions & 0 deletions packages/rest/src/lib/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { RESTPatchAPIChannelJSONBody, Snowflake } from 'discord-api-types/v10';
import type { REST } from '../REST.js';
import { RateLimitError } from '../errors/RateLimitError.js';
import { DEPRECATION_WARNING_PREFIX } from './constants.js';
import { RequestMethod, type RateLimitData, type ResponseLike } from './types.js';

function serializeSearchParam(value: unknown): string | null {
Expand Down Expand Up @@ -140,3 +141,18 @@ export async function sleep(ms: number): Promise<void> {
export function isBufferLike(value: unknown): value is ArrayBuffer | Buffer | Uint8Array | Uint8ClampedArray {
return value instanceof ArrayBuffer || value instanceof Uint8Array || value instanceof Uint8ClampedArray;
}

/**
* Irrespective environment warning.
*
* @remarks Only the message is needed. The deprecation prefix is handled already.
* @param message - A string the warning will emit with
* @internal
*/
export function deprecationWarning(message: string) {
if (typeof globalThis.process === 'undefined') {
console.warn(`${DEPRECATION_WARNING_PREFIX}: ${message}`);
} else {
process.emitWarning(message, DEPRECATION_WARNING_PREFIX);
}
}
1 change: 1 addition & 0 deletions packages/util/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
npm install @discordjs/util
yarn add @discordjs/util
pnpm add @discordjs/util
bun add @discordjs/util
```

## Links
Expand Down
1 change: 1 addition & 0 deletions packages/voice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
npm install @discordjs/voice
yarn add @discordjs/voice
pnpm add @discordjs/voice
bun add @discordjs/voice
```

## Dependencies
Expand Down
2 changes: 1 addition & 1 deletion packages/voice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"homepage": "https://discord.js.org",
"dependencies": {
"@types/ws": "^8.5.5",
"discord-api-types": "0.37.54",
"discord-api-types": "0.37.56",
"prism-media": "^1.3.5",
"tslib": "^2.6.2",
"ws": "^8.13.0"
Expand Down
1 change: 1 addition & 0 deletions packages/ws/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
npm install @discordjs/ws
yarn add @discordjs/ws
pnpm add @discordjs/ws
bun add @discordjs/ws
```

### Optional packages
Expand Down
2 changes: 1 addition & 1 deletion packages/ws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
"@sapphire/async-queue": "^1.5.0",
"@types/ws": "^8.5.5",
"@vladfrangu/async_event_emitter": "^2.2.2",
"discord-api-types": "0.37.54",
"discord-api-types": "0.37.56",
"tslib": "^2.6.2",
"ws": "^8.13.0"
},
Expand Down
Loading