mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 18:43:31 +01:00
feat(REST): enable setting default authPrefix (#7853)
This commit is contained in:
@@ -29,6 +29,12 @@ export interface RESTOptions {
|
|||||||
* @default 'https://discord.com/api'
|
* @default 'https://discord.com/api'
|
||||||
*/
|
*/
|
||||||
api: string;
|
api: string;
|
||||||
|
/**
|
||||||
|
* The authorization prefix to use for requests, useful if you want to use
|
||||||
|
* bearer tokens
|
||||||
|
* @default 'Bot'
|
||||||
|
*/
|
||||||
|
authPrefix: 'Bot' | 'Bearer';
|
||||||
/**
|
/**
|
||||||
* The cdn path
|
* The cdn path
|
||||||
* @default 'https://cdn.discordapp.com'
|
* @default 'https://cdn.discordapp.com'
|
||||||
|
|||||||
@@ -351,7 +351,7 @@ export class RequestManager extends EventEmitter {
|
|||||||
throw new Error('Expected token to be set for this request, but none was present');
|
throw new Error('Expected token to be set for this request, but none was present');
|
||||||
}
|
}
|
||||||
|
|
||||||
headers.Authorization = `${request.authPrefix ?? 'Bot'} ${this.#token}`;
|
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 it's appropriate header
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export const DefaultUserAgent = `DiscordBot (${Package.homepage}, ${Package.vers
|
|||||||
export const DefaultRestOptions: Required<RESTOptions> = {
|
export const DefaultRestOptions: Required<RESTOptions> = {
|
||||||
agent: {},
|
agent: {},
|
||||||
api: 'https://discord.com/api',
|
api: 'https://discord.com/api',
|
||||||
|
authPrefix: 'Bot',
|
||||||
cdn: 'https://cdn.discordapp.com',
|
cdn: 'https://cdn.discordapp.com',
|
||||||
headers: {},
|
headers: {},
|
||||||
invalidRequestWarningInterval: 0,
|
invalidRequestWarningInterval: 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user