chore: Include discord.js in the user agent string (#9267)

* chore: apply user agent string

* fix: enforce even in custom option

* fix: tests

* refactor: simpler way

* docs: add type

* Update packages/discord.js/src/client/BaseClient.js

Co-authored-by: Aura Román <kyradiscord@gmail.com>

* fix: prioritise `option` type check

* types: `static`

* feat: add runtime check

* docs: update default

* refactor: remove Bun

* Update packages/discord.js/src/client/BaseClient.js

Co-authored-by: Almeida <almeidx@pm.me>

* fix: extra whitespace issues

* refactor: `trimEnd()`

---------

Co-authored-by: Aura Román <kyradiscord@gmail.com>
Co-authored-by: Almeida <almeidx@pm.me>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Jiralite
2023-04-01 23:26:44 +01:00
committed by GitHub
parent 1864d37d36
commit ab3328a0e2
5 changed files with 28 additions and 4 deletions

View File

@@ -110,7 +110,7 @@ export interface RESTOptions {
/**
* Extra information to add to the user agent
*
* @defaultValue `Node.js ${process.version}`
* @defaultValue DefaultUserAgentAppendix
*/
userAgentAppendix: string;
/**

View File

@@ -6,6 +6,11 @@ import type { RESTOptions } from '../REST.js';
export const DefaultUserAgent =
`DiscordBot (https://discord.js.org, [VI]{{inject}}[/VI])` as `DiscordBot (https://discord.js.org, ${string})`;
/**
* The default string to append onto the user agent.
*/
export const DefaultUserAgentAppendix = process.release?.name === 'node' ? `Node.js/${process.version}` : '';
export const DefaultRestOptions = {
get agent() {
return new Agent({
@@ -24,7 +29,7 @@ export const DefaultRestOptions = {
rejectOnRateLimit: null,
retries: 3,
timeout: 15_000,
userAgentAppendix: `Node.js ${process.version}`,
userAgentAppendix: DefaultUserAgentAppendix,
version: APIVersion,
hashSweepInterval: 14_400_000, // 4 Hours
hashLifetime: 86_400_000, // 24 Hours