Skip to content

feat: re-emit REST debug logs #10782

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

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/discord.js/src/client/BaseClient.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
'use strict';

const { REST } = require('@discordjs/rest');
const { REST, RESTEvents } = require('@discordjs/rest');
const { AsyncEventEmitter } = require('@vladfrangu/async_event_emitter');
const { Routes } = require('discord-api-types/v10');
const { DiscordjsTypeError, ErrorCodes } = require('../errors/index.js');
const { Events } = require('../util/Events.js');
const { Options } = require('../util/Options.js');
const { flatten } = require('../util/Util.js');

Expand Down Expand Up @@ -53,6 +54,8 @@ class BaseClient extends AsyncEventEmitter {
* @type {REST}
*/
this.rest = new REST(this.options.rest);

this.rest.on(RESTEvents.Debug, message => this.emit(Events.Debug, message));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/rest/src/lib/REST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export class REST extends AsyncEventEmitter<RestEvents> {
sweptHashes.set(key, val);

// Emit debug information
this.emit(RESTEvents.Debug, `Hash ${val.value} for ${key} swept due to lifetime being exceeded`);
this.emit(RESTEvents.Debug, `[REST] Hash ${val.value} for ${key} swept due to lifetime being exceeded`);
}

return shouldSweep;
Expand All @@ -140,7 +140,7 @@ export class REST extends AsyncEventEmitter<RestEvents> {
// Collect inactive handlers
if (inactive) {
sweptHandlers.set(key, val);
this.emit(RESTEvents.Debug, `Handler ${val.id} for ${key} swept due to being inactive`);
this.emit(RESTEvents.Debug, `[REST] Handler ${val.id} for ${key} swept due to being inactive`);
}

return inactive;
Expand Down