diff --git a/packages/rest/src/manager.ts b/packages/rest/src/manager.ts index 256c5e1d7..101a5911d 100644 --- a/packages/rest/src/manager.ts +++ b/packages/rest/src/manager.ts @@ -98,10 +98,17 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage routes: createRoutes(), + createBaseHeaders() { + return { + 'user-agent': `DiscordBot (https://github.com/discordeno/discordeno, v${version})`, + } + }, + checkRateLimits(url, headers) { const authHeader = headers?.authorization ?? '' const ratelimited = rest.rateLimitedPaths.get(`${authHeader}${url}`) + const global = rest.rateLimitedPaths.get('global') const now = Date.now() @@ -161,9 +168,7 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage }, createRequestBody(method, options) { - const headers: Record = { - 'user-agent': `DiscordBot (https://github.com/discordeno/discordeno, v${version})`, - } + const headers = this.createBaseHeaders() if (options?.unauthorized !== true) headers.authorization = `Bot ${rest.token}` diff --git a/packages/rest/src/types.ts b/packages/rest/src/types.ts index b552475df..991c96b79 100644 --- a/packages/rest/src/types.ts +++ b/packages/rest/src/types.ts @@ -176,6 +176,8 @@ export interface RestManager { invalidBucket: InvalidRequestBucket /** The routes that are available for this manager. */ routes: RestRoutes + /** Allows the user to inject custom headers that will be sent with every request. */ + createBaseHeaders: () => Record /** Whether or not the rest manager should keep objects in raw snake case from discord. */ preferSnakeCase: (enabled: boolean) => RestManager /** Check the rate limits for a url or a bucket. */