From 31855578335d2d3070faaaf53c866321a632603b Mon Sep 17 00:00:00 2001 From: DevAndromeda <46562212+DevAndromeda@users.noreply.github.com> Date: Sun, 28 Nov 2021 14:10:27 +0545 Subject: [PATCH] fix(Player): handle emitted errors by default --- src/Player.ts | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Player.ts b/src/Player.ts index 0b90b08..9cbd4fd 100644 --- a/src/Player.ts +++ b/src/Player.ts @@ -29,6 +29,7 @@ class Player extends EventEmitter { public readonly queues = new Collection(); public readonly voiceUtils = new VoiceUtils(); public readonly extractors = new Collection(); + public requiredEvents = ["error", "connectionError"] as string[]; /** * Creates new Discord Player @@ -552,12 +553,25 @@ class Player extends EventEmitter { scanDeps() { const line = "-".repeat(50); const depsReport = generateDependencyReport(); - const extractorReport = this.extractors.map((m) => { - return `${m.name} :: ${m.version || "0.1.0"}`; - }).join("\n"); + const extractorReport = this.extractors + .map((m) => { + return `${m.name} :: ${m.version || "0.1.0"}`; + }) + .join("\n"); return `${depsReport}\n${line}\nLoaded Extractors:\n${extractorReport || "None"}`; } + emit(eventName: U, ...args: Parameters): boolean { + if (this.requiredEvents.includes(eventName) && !super.eventNames().includes(eventName)) { + // eslint-disable-next-line no-console + console.error(...args); + process.emitWarning(`[DiscordPlayerWarning] Unhandled "${eventName}" event! Events ${this.requiredEvents.map(m => `"${m}"`).join(", ")} must have event listeners!`); + return false; + } else { + return super.emit(eventName, ...args); + } + } + /** * Resolves queue * @param {GuildResolvable|Queue} queueLike Queue like object