diff --git a/docs/index.yml b/docs/index.yml index d2ebc01..b2cc511 100644 --- a/docs/index.yml +++ b/docs/index.yml @@ -2,6 +2,10 @@ files: - name: Welcome path: welcome.md +- name: Migrating + files: + - name: Migrating to v5 + path: migrating.md - name: Extractors files: - name: Extractors API @@ -10,6 +14,8 @@ files: - name: Custom Filters path: custom_filters.md + - name: Slash Commands + path: slash_commands.md - name: YouTube files: - name: Using Cookies diff --git a/docs/migrating/migrating.md b/docs/migrating/migrating.md new file mode 100644 index 0000000..6fbe25d --- /dev/null +++ b/docs/migrating/migrating.md @@ -0,0 +1,52 @@ +# Migrating to Discord Player v5 + +We have introduced some breaking changes in Discord Player v5. Which means, your old code will no longer work with v5. +The new update brings new features as well as better management of different things. This also uses the new **[@discordjs/voice](https://github.com/discordjs/voice)** library! + +## Basic Example + +```diff +- player.play(message, query); ++ const queue = player.createQueue(message.guild); ++ const song = await player.search(query); ++ ++ try { ++ await queue.connect(message.member.voice.channel); ++ } catch { ++ message.reply("Could not join your voice channel"); ++ } ++ ++ queue.addTrack(song.tracks[0]); ++ queue.play(); +``` + +> Everything related to music player is moved to `Queue`. + +## How do I reply to the event like v4? + +Since we got rid of `message` parameter in every method of the Discord Player, you no longer have access to the `message` object in events. +Instead, we have added `.metadata` prop as an alternative. This `metadata` can be anything, declared while creating queue: + +```js +const queue = player.createQueue(message.guild, { + metadata: message +}); +``` + +The metadata `message` will always be available in every events emitted for that specific `Queue`. You can access it via `queue.metadata`: + +```js +player.on("trackStart", (queue, track) => { + const channel = queue.metadata.channel; // queue.metadata is your "message" object + channel.send(`🎶 | Started playing **${track.title}**`); +}); +``` + +## How do I stop the player + +You have to use `.destroy()` to destroy the queue. It will also stop the player. + +```js +const queue = player.getQueue(message.guild.id); +if (queue) queue.destroy(); +``` \ No newline at end of file