diff --git a/README.md b/README.md index 9585442..e96a795 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ You need to **init the guild queue using the play() function**, then you are abl ```js // Play a song in the voice channel and init the guild queue client.player.play(voiceChannel, songName); + // Add a song to the queue client.player.addToQueue(guildID, songName); // Clear the queue @@ -64,14 +65,21 @@ client.player.clearQueue(guildID); client.player.getQueue(guildID); // Skip the current song client.player.skip(guildID); + + // Pause client.player.pause(guildID); // Resume client.player.resume(guildID); // Stop client.player.stop(guildID); + // Check if music is playing in a guild client.player.isPlaying(guildID); +// Get the currently playing song +client.player.nowPlaying(guildID); + + // Current song will be repeated indefinitely client.player.setRepeatMode(true); // Current song will no longer be repeated indefinitely @@ -347,7 +355,33 @@ client.on('message', async (message) => { if(command === 'skip'){ let song = await client.player.skip(message.guild.id); - message.channel.send(`${song} skipped!`); + message.channel.send(`${song.name} skipped!`); + } + +}); +``` + +### Now Playing + +To get the currently playing song, use the `client.player.nowPlaying()` function. + +**Usage:** + +```js +client.player.nowPlaying(guildID); +``` + +**Example**: + +```js +client.on('message', async (message) => { + + const args = message.content.slice(settings.prefix.length).trim().split(/ +/g); + const command = args.shift().toLowerCase(); + + if(command === 'now-playing'){ + let song = await client.player.nowPlaying(message.guild.id); + message.channel.send(`Currently playing ${song.name}...`); } }); @@ -375,8 +409,7 @@ client.on('message', async (message) => { // Enable repeat mode client.player.setRepeatMode(true); // Get the current song - let queue = await client.player.getQueue(guildID); - let song = queue.songs[0]; + let song = await client.player.nowPlaying(message.guild.id); message.channel.send(`${song.name} will be repeated indefinitely!`); } @@ -384,8 +417,7 @@ client.on('message', async (message) => { // Disable repeat mode client.player.setRepeatMode(false); // Get the current song - let queue = await client.player.getQueue(guildID); - let song = queue.songs[0]; + let song = await client.player.nowPlaying(message.guild.id); message.channel.send(`${song.name} will no longer be repeated indefinitely!`); } diff --git a/docs/Player.html b/docs/Player.html index 30fa86d..b148915 100644 --- a/docs/Player.html +++ b/docs/Player.html @@ -24,7 +24,7 @@
@@ -1228,6 +1228,157 @@ +
+ + +
+ + + +

nowPlaying(guildID) → {Promise.<Song>}

+ + + + + +
+

Gets the currently playing song.

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
guildID + + +string + + + + + + +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Promise.<Song> + + +
+
+ + + +
+ + +
@@ -1707,6 +1858,157 @@ + + + +
+ + + +

setRepeatMode(enabled) → {Promise.<Void>}

+ + + + + +
+

Enable or disable the repeat mode

+
+ + + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + +
Parameters:
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescription
enabled + + +Boolean + + + + +

Whether the repeat mode should be enabled

+ +
+ + + + + + + + + + + + + + +
+
Returns:
+ + + +
+
+ Type: +
+
+ +Promise.<Void> + + +
+
+ + + +
+ + +
@@ -1891,7 +2193,7 @@ -

skip(guildID) → {Promise.<Queue>}

+

skip(guildID) → {Promise.<Song>}

@@ -2023,7 +2325,7 @@
-Promise.<Queue> +Promise.<Song>
diff --git a/src/Player.js b/src/Player.js index 2b9b873..fe9b32e 100644 --- a/src/Player.js +++ b/src/Player.js @@ -258,6 +258,22 @@ class Player { }); } + /** + * Gets the currently playing song. + * @param {string} guildID + * @returns {Promise} + */ + nowPlaying(guildID){ + return new Promise(async(resolve, reject) => { + // Gets guild queue + let queue = this.queues.find((g) => g.guildID === guildID); + if(!queue) reject('Not playing'); + let currentSong = queue.songs[0]; + // Resolves the current song + resolve(currentSong); + }); + } + /** * Enable or disable the repeat mode * @param {Boolean} enabled Whether the repeat mode should be enabled