diff --git a/src/buttons/music/queueList-next.ts b/src/buttons/music/queueList-next.ts index 6876680..d3f4263 100644 --- a/src/buttons/music/queueList-next.ts +++ b/src/buttons/music/queueList-next.ts @@ -1,4 +1,4 @@ -import { Player } from "discord-player"; +import { useQueue } from "discord-player"; import { ActionRowBuilder, ButtonBuilder, @@ -30,11 +30,8 @@ export default { page++; } - // Get player - const player = Player.singleton(client); - // Get queue - const queue = player.queues.get(interaction.guildId ?? ""); + const queue = useQueue(interaction.guildId ?? ""); const embed = new EmbedBuilder(); const rows = []; diff --git a/src/buttons/music/queueList-prec.ts b/src/buttons/music/queueList-prec.ts index 1bfb691..40306ca 100644 --- a/src/buttons/music/queueList-prec.ts +++ b/src/buttons/music/queueList-prec.ts @@ -1,4 +1,4 @@ -import { Player } from "discord-player"; +import { useQueue } from "discord-player"; import { ActionRowBuilder, ButtonBuilder, @@ -30,11 +30,8 @@ export default { page--; } - // Get player - const player = Player.singleton(client); - // Get queue - const queue = player.queues.get(interaction.guildId ?? ""); + const queue = useQueue(interaction.guildId ?? ""); const embed = new EmbedBuilder(); const rows = []; diff --git a/src/commands/music/lyrics.ts b/src/commands/music/lyrics.ts index 54f33a0..b770fca 100644 --- a/src/commands/music/lyrics.ts +++ b/src/commands/music/lyrics.ts @@ -1,5 +1,5 @@ import { SlashCommandBuilder } from "@discordjs/builders"; -import { Player } from "discord-player"; +import { Player, useQueue } from "discord-player"; import { ChatInputCommandInteraction, Client, EmbedBuilder } from "discord.js"; import { getLocale, getLocalizations } from "../../utils/locales"; import { getFilename } from "../../utils/misc"; @@ -53,7 +53,7 @@ export default { return await interaction.followUp(`❌ | ${loc.get("c_lyrics2")} \`${request}\``); } } else { - const queue = player.queues.get(interaction.guildId ?? ""); + const queue = useQueue(interaction.guildId ?? ""); if (queue) { const title = queue.history.currentTrack?.title; if (title) { diff --git a/src/commands/music/pause.ts b/src/commands/music/pause.ts index 421826e..2f8dc3d 100644 --- a/src/commands/music/pause.ts +++ b/src/commands/music/pause.ts @@ -1,5 +1,5 @@ import { SlashCommandBuilder } from "@discordjs/builders"; -import { Player } from "discord-player"; +import { useQueue } from "discord-player"; import { ChatInputCommandInteraction, Client, EmbedBuilder } from "discord.js"; import { getLocale, getLocalizations } from "../../utils/locales"; import { getFilename } from "../../utils/misc"; @@ -23,8 +23,7 @@ export default { interaction: async (interaction: ChatInputCommandInteraction, client: Client) => { const loc = getLocale(client, interaction.locale); - const player = Player.singleton(client); - const queue = player.queues.get(interaction.guildId ?? ""); + const queue = useQueue(interaction.guildId ?? ""); if (queue) { const embed = new EmbedBuilder(); diff --git a/src/commands/music/play.ts b/src/commands/music/play.ts index bcd49e9..8705aeb 100644 --- a/src/commands/music/play.ts +++ b/src/commands/music/play.ts @@ -9,7 +9,7 @@ import { import { Metadata } from "../../utils/metadata"; import { getLocale, getLocalizations } from "../../utils/locales"; import { getFilename } from "../../utils/misc"; -import { Player } from "discord-player"; +import { Player, useQueue } from "discord-player"; export default { scope: () => [], @@ -73,7 +73,7 @@ export default { if (!query) { // Now playing - const queue = player.queues.get(interaction.guildId ?? ""); + const queue = useQueue(interaction.guildId ?? ""); if (queue) { const track = queue.history.currentTrack; @@ -130,6 +130,7 @@ export default { title = result.playlist.title; } else { // TODO: Ask user which result to choose + // Maybe use https://discordjs.guide/interactions/select-menus.html#building-and-sending-select-menus ? const track = result.tracks[0]; queue.addTrack(track); diff --git a/src/commands/music/queue.ts b/src/commands/music/queue.ts index 926d336..98c874c 100644 --- a/src/commands/music/queue.ts +++ b/src/commands/music/queue.ts @@ -1,5 +1,5 @@ import { SlashCommandBuilder } from "@discordjs/builders"; -import { Player } from "discord-player"; +import { useQueue } from "discord-player"; import { ActionRowBuilder, ButtonBuilder, @@ -93,8 +93,7 @@ export default { const filename = getFilename(__filename); const loc = getLocale(client, interaction.locale); - const player = Player.singleton(client); - const queue = player.queues.get(interaction.guildId ?? ""); + const queue = useQueue(interaction.guildId ?? ""); const embed = new EmbedBuilder(); const rows = []; diff --git a/src/commands/music/repeat.ts b/src/commands/music/repeat.ts index 113d0b7..44fb33c 100644 --- a/src/commands/music/repeat.ts +++ b/src/commands/music/repeat.ts @@ -1,5 +1,5 @@ import { SlashCommandBuilder } from "@discordjs/builders"; -import { Player, QueueRepeatMode } from "discord-player"; +import { QueueRepeatMode, useQueue } from "discord-player"; import { ChatInputCommandInteraction, Client } from "discord.js"; import { getLocale, getLocalizations } from "../../utils/locales"; import { getFilename } from "../../utils/misc"; @@ -64,8 +64,7 @@ export default { const filename = getFilename(__filename); const loc = getLocale(client, interaction.locale); - const player = Player.singleton(client); - const queue = player.queues.get(interaction.guildId ?? ""); + const queue = useQueue(interaction.guildId ?? ""); if (queue) { const subcommand = interaction.options.getSubcommand(); diff --git a/src/commands/music/skip.ts b/src/commands/music/skip.ts index 1bd11d5..fffb5a3 100644 --- a/src/commands/music/skip.ts +++ b/src/commands/music/skip.ts @@ -1,5 +1,5 @@ import { SlashCommandBuilder } from "@discordjs/builders"; -import { Player } from "discord-player"; +import { useQueue } from "discord-player"; import { ChatInputCommandInteraction, Client } from "discord.js"; import { getLocale, getLocalizations } from "../../utils/locales"; import { getFilename } from "../../utils/misc"; @@ -37,8 +37,7 @@ export default { const filename = getFilename(__filename); const loc = getLocale(client, interaction.locale); - const player = Player.singleton(client); - const queue = player.queues.get(interaction.guildId ?? ""); + const queue = useQueue(interaction.guildId ?? ""); const id = interaction.options.getNumber(loc_default?.get(`c_${filename}_opt1_name`) as string); diff --git a/src/events/player/connectionError.ts b/src/events/player/connectionError.ts deleted file mode 100644 index 892eee7..0000000 --- a/src/events/player/connectionError.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { GuildQueue } from "discord-player"; -import { Metadata } from "../../utils/metadata"; - -/** https://discord-player.js.org/docs/main/master/typedef/PlayerEvents */ -export default (_: GuildQueue, error: Error) => { - console.error(error); -}; diff --git a/src/events/player/error.ts b/src/events/player/error.ts deleted file mode 100644 index 892eee7..0000000 --- a/src/events/player/error.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { GuildQueue } from "discord-player"; -import { Metadata } from "../../utils/metadata"; - -/** https://discord-player.js.org/docs/main/master/typedef/PlayerEvents */ -export default (_: GuildQueue, error: Error) => { - console.error(error); -}; diff --git a/src/events/player/trackStart.ts b/src/events/player/playerStart.ts similarity index 91% rename from src/events/player/trackStart.ts rename to src/events/player/playerStart.ts index 30d6b49..55cd603 100644 --- a/src/events/player/trackStart.ts +++ b/src/events/player/playerStart.ts @@ -4,7 +4,7 @@ import { Client } from "discord.js"; import { Metadata } from "../../utils/metadata"; import { emojiPng } from "../../utils/misc"; -/** https://discord-player.js.org/docs/main/master/typedef/PlayerEvents */ +/** https://discord-player.js.org/docs/types/discord-player/GuildQueueEvents */ export default (queue: GuildQueue, track: Track, client: Client) => { const loc_default = client.locales.get(client.config.default_lang); diff --git a/src/utils/client.ts b/src/utils/client.ts index 8aa651b..79c6f71 100644 --- a/src/utils/client.ts +++ b/src/utils/client.ts @@ -38,7 +38,7 @@ export default async () => { list: new Collection(), }; - const player = Player.singleton(client, { + const player = new Player(client, { ytdlOptions: { filter: "audioonly", },