Add nowPlaying() function
This commit is contained in:
parent
7b834cc9f2
commit
8ca94e98be
3 changed files with 358 additions and 8 deletions
42
README.md
42
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!`);
|
||||
}
|
||||
|
||||
|
|
308
docs/Player.html
308
docs/Player.html
|
@ -24,7 +24,7 @@
|
|||
<label for="nav-trigger" class="overlay"></label>
|
||||
|
||||
<nav>
|
||||
<li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading">Classes</li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Player.html">Player</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#addToQueue">addToQueue</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#clearQueue">clearQueue</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#getQueue">getQueue</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#isPlaying">isPlaying</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#pause">pause</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#play">play</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#resume">resume</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#setVolume">setVolume</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#skip">skip</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#stop">stop</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Queue.html">Queue</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Song.html">Song</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Util.html">Util</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Util.html#.getFirstYoutubeResult">getFirstYoutubeResult</a></span></li><li class="nav-heading">Events</li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Queue.html#event:end">end</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Queue.html#event:songChanged">songChanged</a></span></li><li class="nav-heading"><a href="global.html">Globals</a></li>
|
||||
<li class="nav-link nav-home-link"><a href="index.html">Home</a></li><li class="nav-heading">Classes</li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Player.html">Player</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#addToQueue">addToQueue</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#clearQueue">clearQueue</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#getQueue">getQueue</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#isPlaying">isPlaying</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#nowPlaying">nowPlaying</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#pause">pause</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#play">play</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#resume">resume</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#setRepeatMode">setRepeatMode</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#setVolume">setVolume</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#skip">skip</a></span></li><li class="nav-item"><span class="nav-item-type type-function">F</span><span class="nav-item-name"><a href="Player.html#stop">stop</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Queue.html">Queue</a></span></li><li class="nav-heading"><span class="nav-item-type type-class">C</span><span class="nav-item-name"><a href="Song.html">Song</a></span></li><li class="nav-heading">Events</li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Queue.html#event:channelEmpty">channelEmpty</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Queue.html#event:end">end</a></span></li><li class="nav-heading"><span class="nav-item-type type-event">E</span><span class="nav-item-name"><a href="Queue.html#event:songChanged">songChanged</a></span></li><li class="nav-heading"><a href="global.html">Globals</a></li>
|
||||
</nav>
|
||||
|
||||
<div id="main">
|
||||
|
@ -1228,6 +1228,157 @@
|
|||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="section-method">
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="nowPlaying"><span class="type-signature"></span>nowPlaying<span class="signature">(guildID)</span><span class="type-signature"> → {Promise.<<a href="Song.html">Song</a>>}</span></h4>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="description">
|
||||
<p>Gets the currently playing song.</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h5>Parameters:</h5>
|
||||
|
||||
|
||||
<table class="params">
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
<th>Name</th>
|
||||
|
||||
|
||||
<th>Type</th>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<th class="last">Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="name"><code>guildID</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type"><code>string</code></span>
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<td class="description last">
|
||||
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="section-returns">
|
||||
<h5>Returns:</h5>
|
||||
|
||||
|
||||
|
||||
<dl class="param-type">
|
||||
<dt>
|
||||
Type:
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
<span class="param-type"><code>Promise.<<a href="Song.html">Song</a>></code></span>
|
||||
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
@ -1707,6 +1858,157 @@
|
|||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="section-method">
|
||||
|
||||
|
||||
|
||||
<h4 class="name" id="setRepeatMode"><span class="type-signature"></span>setRepeatMode<span class="signature">(enabled)</span><span class="type-signature"> → {Promise.<Void>}</span></h4>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="description">
|
||||
<p>Enable or disable the repeat mode</p>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<dl class="details">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<h5>Parameters:</h5>
|
||||
|
||||
|
||||
<table class="params">
|
||||
<thead>
|
||||
<tr>
|
||||
|
||||
<th>Name</th>
|
||||
|
||||
|
||||
<th>Type</th>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<th class="last">Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
|
||||
|
||||
<tr>
|
||||
|
||||
<td class="name"><code>enabled</code></td>
|
||||
|
||||
|
||||
<td class="type">
|
||||
|
||||
|
||||
<span class="param-type"><code>Boolean</code></span>
|
||||
|
||||
|
||||
|
||||
</td>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<td class="description last">
|
||||
<p>Whether the repeat mode should be enabled</p>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div class="section-returns">
|
||||
<h5>Returns:</h5>
|
||||
|
||||
|
||||
|
||||
<dl class="param-type">
|
||||
<dt>
|
||||
Type:
|
||||
</dt>
|
||||
<dd>
|
||||
|
||||
<span class="param-type"><code>Promise.<Void></code></span>
|
||||
|
||||
|
||||
</dd>
|
||||
</dl>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
@ -1891,7 +2193,7 @@
|
|||
|
||||
|
||||
|
||||
<h4 class="name" id="skip"><span class="type-signature"></span>skip<span class="signature">(guildID)</span><span class="type-signature"> → {Promise.<<a href="Queue.html">Queue</a>>}</span></h4>
|
||||
<h4 class="name" id="skip"><span class="type-signature"></span>skip<span class="signature">(guildID)</span><span class="type-signature"> → {Promise.<<a href="Song.html">Song</a>>}</span></h4>
|
||||
|
||||
|
||||
|
||||
|
@ -2023,7 +2325,7 @@
|
|||
</dt>
|
||||
<dd>
|
||||
|
||||
<span class="param-type"><code>Promise.<<a href="Queue.html">Queue</a>></code></span>
|
||||
<span class="param-type"><code>Promise.<<a href="Song.html">Song</a>></code></span>
|
||||
|
||||
|
||||
</dd>
|
||||
|
|
|
@ -258,6 +258,22 @@ class Player {
|
|||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the currently playing song.
|
||||
* @param {string} guildID
|
||||
* @returns {Promise<Song>}
|
||||
*/
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue