fix(Player): handle emitted errors by default
This commit is contained in:
parent
77d2eeeffe
commit
3185557833
1 changed files with 17 additions and 3 deletions
|
@ -29,6 +29,7 @@ class Player extends EventEmitter<PlayerEvents> {
|
|||
public readonly queues = new Collection<Snowflake, Queue>();
|
||||
public readonly voiceUtils = new VoiceUtils();
|
||||
public readonly extractors = new Collection<string, ExtractorModel>();
|
||||
public requiredEvents = ["error", "connectionError"] as string[];
|
||||
|
||||
/**
|
||||
* Creates new Discord Player
|
||||
|
@ -552,12 +553,25 @@ class Player extends EventEmitter<PlayerEvents> {
|
|||
scanDeps() {
|
||||
const line = "-".repeat(50);
|
||||
const depsReport = generateDependencyReport();
|
||||
const extractorReport = this.extractors.map((m) => {
|
||||
const extractorReport = this.extractors
|
||||
.map((m) => {
|
||||
return `${m.name} :: ${m.version || "0.1.0"}`;
|
||||
}).join("\n");
|
||||
})
|
||||
.join("\n");
|
||||
return `${depsReport}\n${line}\nLoaded Extractors:\n${extractorReport || "None"}`;
|
||||
}
|
||||
|
||||
emit<U extends keyof PlayerEvents>(eventName: U, ...args: Parameters<PlayerEvents[U]>): 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
|
||||
|
|
Loading…
Reference in a new issue