add debug event for discord player

This commit is contained in:
Mylloon 2024-09-18 16:33:20 +02:00
parent 23d3918459
commit 4e98a31d03
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 14 additions and 4 deletions

View file

@ -1,13 +1,24 @@
import { Player, PlayerEvents, useMainPlayer } from "discord-player";
import { PlayerEvents, useMainPlayer } from "discord-player";
import { Client } from "discord.js";
import { readdir } from "fs/promises";
/** Load all the events */
export default async (client: Client) => {
export default async (client: Client, isDev: boolean) => {
const events_categories = (await readdir(__dirname)).filter(
(element) => !element.endsWith(".js") && !element.endsWith(".ts"),
);
const player = useMainPlayer();
if (isDev) {
player.on("debug", async (message) => {
console.log(`General player debug event: ${message}`);
});
player.events.on("debug", async (_, message) => {
console.log(`Player debug event: ${message}`);
});
}
events_categories.forEach(async (event_category) => {
// Retrieve events
const events = await readdir(`${__dirname}/${event_category}`);
@ -29,7 +40,6 @@ export default async (client: Client) => {
const event_type = event_type_ext.join(".");
if (event_category == "player") {
const player = useMainPlayer() as Player;
if (once) {
// eslint-disable-next-line
return player.events.once(event_type as keyof PlayerEvents, (...args: any[]) => {

View file

@ -21,7 +21,7 @@ export const run = async (isDev: boolean) => {
// Events Discord.JS and Player
const events_name = "Events";
await loadEvents(client)
await loadEvents(client, isDev)
.then(() => console.log(logStart(events_name, true)))
.catch((err) => {
console.error(err);