diff --git a/src/commands/music/play.ts b/src/commands/music/play.ts index 2edd3b0..d4aa9a3 100644 --- a/src/commands/music/play.ts +++ b/src/commands/music/play.ts @@ -5,9 +5,9 @@ import { GuildResolvable, VoiceBasedChannel, } from "discord.js"; +import { Metadata } from "../../modules/metadata"; import { getLocalizations } from "../../utils/locales"; import { getFilename } from "../../utils/misc"; -import { Metadata } from "../../modules/metadata"; export default { scope: () => [], @@ -68,7 +68,7 @@ export default { const queue = client.player.createQueue(interaction.guild as GuildResolvable, { metadata: { channel: interaction.channel, - }, + } as Metadata, }); // Verify vc connection @@ -93,16 +93,8 @@ export default { return await interaction.followUp({ content: `❌ | \`${query}\` introuvable.` }); } - // TMP - client.player.on("error", () => console.log("error")); - client.player.on("connectionError", () => console.log("error")); - client.player.on("trackStart", (q, t) => - (q.metadata as Metadata).channel?.send(`🎶 | Joue \`${t.title}\`.`) - ); - // + queue.play(track); - await queue.play(track); - - return await interaction.followUp({ content: `⏱️ | Chargement de \`${track.title}\`.` }); + return await interaction.followUp({ content: `⏱️ | Chargement de \`${track.title}\`...` }); }, }; diff --git a/src/events/loader.ts b/src/events/loader.ts index 9446bbf..bf557ce 100644 --- a/src/events/loader.ts +++ b/src/events/loader.ts @@ -1,3 +1,4 @@ +import { PlayerEvents } from "discord-player"; import { Client } from "discord.js"; import { readdir } from "fs/promises"; @@ -27,6 +28,13 @@ export default async (client: Client) => { } const event_type = event_type_ext.join("."); + if (event_category == "player") { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return client.player.on(event_type as keyof PlayerEvents, (...args: any) => + execute(...args, client) + ); + } + if (once) { return client.once(event_type, (...args) => { execute(...args, client); diff --git a/src/events/player/connectionError.ts b/src/events/player/connectionError.ts new file mode 100644 index 0000000..ad374ab --- /dev/null +++ b/src/events/player/connectionError.ts @@ -0,0 +1,6 @@ +import { Queue } from "discord-player"; + +/** https://discord-player.js.org/docs/main/master/typedef/PlayerEvents */ +export default async (_: Queue, error: Error) => { + console.error(error); +}; diff --git a/src/events/player/error.ts b/src/events/player/error.ts new file mode 100644 index 0000000..ad374ab --- /dev/null +++ b/src/events/player/error.ts @@ -0,0 +1,6 @@ +import { Queue } from "discord-player"; + +/** https://discord-player.js.org/docs/main/master/typedef/PlayerEvents */ +export default async (_: Queue, error: Error) => { + console.error(error); +}; diff --git a/src/events/player/trackStart.ts b/src/events/player/trackStart.ts new file mode 100644 index 0000000..e448d11 --- /dev/null +++ b/src/events/player/trackStart.ts @@ -0,0 +1,7 @@ +import { Queue, Track } from "discord-player"; +import { Metadata } from "../../modules/metadata"; + +/** https://discord-player.js.org/docs/main/master/typedef/PlayerEvents */ +export default async (queue: Queue, track: Track) => { + (queue.metadata as Metadata).channel?.send(`🎶 | Joue \`${track.title}\`.`); +};