📝 Use track instead of song
This commit is contained in:
parent
e1e51ddf03
commit
48a4ddb037
1 changed files with 66 additions and 66 deletions
132
README.md
132
README.md
|
@ -46,7 +46,7 @@ client.login(settings.token);
|
||||||
```
|
```
|
||||||
|
|
||||||
You can pass a third parameter when instantiating the class Player: the **options** object:
|
You can pass a third parameter when instantiating the class Player: the **options** object:
|
||||||
**options.leaveOnEnd**: whether the bot should leave the voice channel when there is no more song in the queue.
|
**options.leaveOnEnd**: whether the bot should leave the voice channel when there is no more track in the queue.
|
||||||
**options.leaveOnStop**: whether the bot should leave the voice channel when the `stop()` function is used.
|
**options.leaveOnStop**: whether the bot should leave the voice channel when the `stop()` function is used.
|
||||||
**options.leaveOnEmpty**: whether the bot should leave the voice channel if there is no more member in it.
|
**options.leaveOnEmpty**: whether the bot should leave the voice channel if there is no more member in it.
|
||||||
|
|
||||||
|
@ -55,19 +55,19 @@ You can pass a third parameter when instantiating the class Player: the **option
|
||||||
You need to **init the guild queue using the play() function**, then you are able to manage the queue using the following functions:
|
You need to **init the guild queue using the play() function**, then you are able to manage the queue using the following functions:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
// Play a song in the voice channel and init the guild queue
|
// Play a track in the voice channel and init the guild queue
|
||||||
client.player.play(voiceChannel, songName);
|
client.player.play(voiceChannel, trackName);
|
||||||
|
|
||||||
// Add a song to the queue
|
// Add a track to the queue
|
||||||
client.player.addToQueue(guildID, songName);
|
client.player.addToQueue(guildID, trackName);
|
||||||
// Clear the queue
|
// Clear the queue
|
||||||
client.player.clearQueue(guildID);
|
client.player.clearQueue(guildID);
|
||||||
// Get the queue
|
// Get the queue
|
||||||
client.player.getQueue(guildID);
|
client.player.getQueue(guildID);
|
||||||
// Skip the current song
|
// Skip the current track
|
||||||
client.player.skip(guildID);
|
client.player.skip(guildID);
|
||||||
// Remove a song from the queue using the index number
|
// Remove a track from the queue using the index number
|
||||||
client.player.remove(guildID, song);
|
client.player.remove(guildID, track);
|
||||||
|
|
||||||
|
|
||||||
// Pause
|
// Pause
|
||||||
|
@ -79,13 +79,13 @@ client.player.stop(guildID);
|
||||||
|
|
||||||
// Check if music is playing in a guild
|
// Check if music is playing in a guild
|
||||||
client.player.isPlaying(guildID);
|
client.player.isPlaying(guildID);
|
||||||
// Get the currently playing song
|
// Get the currently playing trac
|
||||||
client.player.nowPlaying(guildID);
|
client.player.nowPlaying(guildID);
|
||||||
|
|
||||||
|
|
||||||
// Current song will be repeated indefinitely
|
// Current track will be repeated indefinitely
|
||||||
client.player.setRepeatMode(guildID, true);
|
client.player.setRepeatMode(guildID, true);
|
||||||
// Current song will no longer be repeated indefinitely
|
// Current track will no longer be repeated indefinitely
|
||||||
client.player.setRepeatMode(guildID, false);
|
client.player.setRepeatMode(guildID, false);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -96,8 +96,8 @@ client.player.getQueue(guildID)
|
||||||
.on('end', () => {
|
.on('end', () => {
|
||||||
message.channel.send('There is no more music in the queue!');
|
message.channel.send('There is no more music in the queue!');
|
||||||
})
|
})
|
||||||
.on('songChanged', (oldSong, newSong) => {
|
.on('trackChanged', (oldTrack, newTrack) => {
|
||||||
message.channel.send(`Now playing ${newSong.name}...`);
|
message.channel.send(`Now playing ${newTrack.name}...`);
|
||||||
})
|
})
|
||||||
.on('channelEmpty', () => {
|
.on('channelEmpty', () => {
|
||||||
message.channel.send('Stop playing, there is no more member in the voice channel...');
|
message.channel.send('Stop playing, there is no more member in the voice channel...');
|
||||||
|
@ -108,12 +108,12 @@ client.player.getQueue(guildID)
|
||||||
|
|
||||||
### Play
|
### Play
|
||||||
|
|
||||||
To play a song, use the `client.player.play()` function.
|
To play a track, use the `client.player.play()` function.
|
||||||
|
|
||||||
**Usage:**
|
**Usage:**
|
||||||
|
|
||||||
```js
|
```js
|
||||||
client.player.play(voiceChannel, songName, requestedBy);
|
client.player.play(voiceChannel, trackName, requestedBy);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Example**:
|
**Example**:
|
||||||
|
@ -128,15 +128,15 @@ client.on('message', async (message) => {
|
||||||
// will play "Despacito" in the member voice channel
|
// will play "Despacito" in the member voice channel
|
||||||
|
|
||||||
if(command === 'play'){
|
if(command === 'play'){
|
||||||
let song = await client.player.play(message.member.voice.channel, args[0], message.member.user.tag);
|
let track = await client.player.play(message.member.voice.channel, args[0], message.member.user.tag);
|
||||||
message.channel.send(`Currently playing ${song.name}! - Requested by ${song.requestedBy}`);
|
message.channel.send(`Currently playing ${track.name}! - Requested by ${track.requestedBy}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Pause
|
### Pause
|
||||||
|
|
||||||
To pause the current song, use the `client.player.pause()` function.
|
To pause the current track, use the `client.player.pause()` function.
|
||||||
|
|
||||||
**Usage:**
|
**Usage:**
|
||||||
|
|
||||||
|
@ -153,8 +153,8 @@ client.on('message', async (message) => {
|
||||||
const command = args.shift().toLowerCase();
|
const command = args.shift().toLowerCase();
|
||||||
|
|
||||||
if(command === 'pause'){
|
if(command === 'pause'){
|
||||||
let song = await client.player.pause(message.guild.id);
|
let track = await client.player.pause(message.guild.id);
|
||||||
message.channel.send(`${song.name} paused!`);
|
message.channel.send(`${track.name} paused!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -162,7 +162,7 @@ client.on('message', async (message) => {
|
||||||
|
|
||||||
### Resume
|
### Resume
|
||||||
|
|
||||||
To resume the current song, use the `client.player.resume()` function.
|
To resume the current track, use the `client.player.resume()` function.
|
||||||
|
|
||||||
**Usage:**
|
**Usage:**
|
||||||
|
|
||||||
|
@ -179,8 +179,8 @@ client.on('message', async (message) => {
|
||||||
const command = args.shift().toLowerCase();
|
const command = args.shift().toLowerCase();
|
||||||
|
|
||||||
if(command === 'resume'){
|
if(command === 'resume'){
|
||||||
let song = await client.player.resume(message.guild.id);
|
let track = await client.player.resume(message.guild.id);
|
||||||
message.channel.send(`${song.name} resumed!`);
|
message.channel.send(`${track.name} resumed!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -240,17 +240,17 @@ client.on('message', (message) => {
|
||||||
|
|
||||||
### AddToQueue
|
### AddToQueue
|
||||||
|
|
||||||
To add a song to the queue, use the `client.player.addToQueue()` function.
|
To add a track to the queue, use the `client.player.addToQueue()` function.
|
||||||
|
|
||||||
**Usage:**
|
**Usage:**
|
||||||
|
|
||||||
```js
|
```js
|
||||||
client.player.addToQueue(guildID, songName);
|
client.player.addToQueue(guildID, trackName);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Example:**
|
**Example:**
|
||||||
|
|
||||||
In this example, you will see how to add a song to the queue if one is already playing.
|
In this example, you will see how to add a track to the queue if one is already playing.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
client.on('message', async (message) => {
|
client.on('message', async (message) => {
|
||||||
|
@ -259,16 +259,16 @@ client.on('message', async (message) => {
|
||||||
const command = args.shift().toLowerCase();
|
const command = args.shift().toLowerCase();
|
||||||
|
|
||||||
if(command === 'play'){
|
if(command === 'play'){
|
||||||
let aSongIsAlreadyPlaying = client.player.isPlaying(message.guild.id);
|
let aTrackIsAlreadyPlaying = client.player.isPlaying(message.guild.id);
|
||||||
// If there's already a song playing
|
// If there's already a track playing
|
||||||
if(aSongIsAlreadyPlaying){
|
if(aTrackIsAlreadyPlaying){
|
||||||
// Add the song to the queue
|
// Add the track to the queue
|
||||||
let song = await client.player.addToQueue(message.guild.id, args[0]);
|
let track = await client.player.addToQueue(message.guild.id, args[0]);
|
||||||
message.channel.send(`${song.name} added to queue!`);
|
message.channel.send(`${track.name} added to queue!`);
|
||||||
} else {
|
} else {
|
||||||
// Else, play the song
|
// Else, play the track
|
||||||
let song = await client.player.play(message.member.voice.channel, args[0]);
|
let track = await client.player.play(message.member.voice.channel, args[0]);
|
||||||
message.channel.send(`Currently playing ${song.name}!`);
|
message.channel.send(`Currently playing ${track.name}!`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -321,8 +321,8 @@ client.on('message', (message) => {
|
||||||
|
|
||||||
if(command === 'queue'){
|
if(command === 'queue'){
|
||||||
let queue = await client.player.getQueue(message.guild.id);
|
let queue = await client.player.getQueue(message.guild.id);
|
||||||
message.channel.send('Server queue:\n'+(queue.songs.map((song, i) => {
|
message.channel.send('Server queue:\n'+(queue.tracks.map((track, i) => {
|
||||||
return `${i === 0 ? 'Current' : `#${i+1}`} - ${song.name} | ${song.author}`
|
return `${i === 0 ? 'Current' : `#${i+1}`} - ${track.name} | ${track.author}`
|
||||||
}).join('\n')));
|
}).join('\n')));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,7 +341,7 @@ client.on('message', (message) => {
|
||||||
|
|
||||||
### Skip
|
### Skip
|
||||||
|
|
||||||
To skip the current song, use the `client.player.skip()` function.
|
To skip the current track, use the `client.player.skip()` function.
|
||||||
|
|
||||||
**Usage:**
|
**Usage:**
|
||||||
|
|
||||||
|
@ -358,8 +358,8 @@ client.on('message', async (message) => {
|
||||||
const command = args.shift().toLowerCase();
|
const command = args.shift().toLowerCase();
|
||||||
|
|
||||||
if(command === 'skip'){
|
if(command === 'skip'){
|
||||||
let song = await client.player.skip(message.guild.id);
|
let track = await client.player.skip(message.guild.id);
|
||||||
message.channel.send(`${song.name} skipped!`);
|
message.channel.send(`${track.name} skipped!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -367,7 +367,7 @@ client.on('message', async (message) => {
|
||||||
|
|
||||||
### Now Playing
|
### Now Playing
|
||||||
|
|
||||||
To get the currently playing song, use the `client.player.nowPlaying()` function.
|
To get the currently playing track, use the `client.player.nowPlaying()` function.
|
||||||
|
|
||||||
**Usage:**
|
**Usage:**
|
||||||
|
|
||||||
|
@ -384,8 +384,8 @@ client.on('message', async (message) => {
|
||||||
const command = args.shift().toLowerCase();
|
const command = args.shift().toLowerCase();
|
||||||
|
|
||||||
if(command === 'now-playing'){
|
if(command === 'now-playing'){
|
||||||
let song = await client.player.nowPlaying(message.guild.id);
|
let track = await client.player.nowPlaying(message.guild.id);
|
||||||
message.channel.send(`Currently playing ${song.name}...`);
|
message.channel.send(`Currently playing ${track.name}...`);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -393,7 +393,7 @@ client.on('message', async (message) => {
|
||||||
|
|
||||||
### Repeat
|
### Repeat
|
||||||
|
|
||||||
To repeat the current song, use the `client.player.setRepeatMode()` function.
|
To repeat the current track, use the `client.player.setRepeatMode()` function.
|
||||||
|
|
||||||
**Usage:**
|
**Usage:**
|
||||||
|
|
||||||
|
@ -412,17 +412,17 @@ client.on('message', async (message) => {
|
||||||
if(command === 'enable-repeat'){
|
if(command === 'enable-repeat'){
|
||||||
// Enable repeat mode
|
// Enable repeat mode
|
||||||
client.player.setRepeatMode(message.guild.id, true);
|
client.player.setRepeatMode(message.guild.id, true);
|
||||||
// Get the current song
|
// Get the current track
|
||||||
let song = await client.player.nowPlaying(message.guild.id);
|
let track = await client.player.nowPlaying(message.guild.id);
|
||||||
message.channel.send(`${song.name} will be repeated indefinitely!`);
|
message.channel.send(`${track.name} will be repeated indefinitely!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(command === 'disable-repeat'){
|
if(command === 'disable-repeat'){
|
||||||
// Disable repeat mode
|
// Disable repeat mode
|
||||||
client.player.setRepeatMode(message.guild.id, false);
|
client.player.setRepeatMode(message.guild.id, false);
|
||||||
// Get the current song
|
// Get the current track
|
||||||
let song = await client.player.nowPlaying(message.guild.id);
|
let track = await client.player.nowPlaying(message.guild.id);
|
||||||
message.channel.send(`${song.name} will no longer be repeated indefinitely!`);
|
message.channel.send(`${track.name} will no longer be repeated indefinitely!`);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -430,12 +430,12 @@ client.on('message', async (message) => {
|
||||||
|
|
||||||
### Remove
|
### Remove
|
||||||
|
|
||||||
To remove a song from the queue, use the `client.player.remove()` function.
|
To remove a track from the queue, use the `client.player.remove()` function.
|
||||||
|
|
||||||
**Usage:**
|
**Usage:**
|
||||||
|
|
||||||
```js
|
```js
|
||||||
client.player.remove(guildID, song);
|
client.player.remove(guildID, track);
|
||||||
```
|
```
|
||||||
|
|
||||||
**Example:**
|
**Example:**
|
||||||
|
@ -447,9 +447,9 @@ client.on('message', async (message) => {
|
||||||
const command = args.shift().toLowerCase();
|
const command = args.shift().toLowerCase();
|
||||||
|
|
||||||
if(command === 'remove'){
|
if(command === 'remove'){
|
||||||
// Removes a song from the queue
|
// Removes a track from the queue
|
||||||
client.player.remove(message.guild.id, args[0]).then(() => {
|
client.player.remove(message.guild.id, args[0]).then(() => {
|
||||||
message.channel.send('Removed song!');
|
message.channel.send('Removed track!');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -457,7 +457,7 @@ client.on('message', async (message) => {
|
||||||
|
|
||||||
## Info Messages
|
## Info Messages
|
||||||
|
|
||||||
You can send a message when the queue ends or when the song changes:
|
You can send a message when the queue ends or when the track changes:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
client.on('message', (message) => {
|
client.on('message', (message) => {
|
||||||
|
@ -466,15 +466,15 @@ client.on('message', (message) => {
|
||||||
const command = args.shift().toLowerCase();
|
const command = args.shift().toLowerCase();
|
||||||
|
|
||||||
if(command === 'play'){
|
if(command === 'play'){
|
||||||
let song = await client.player.play(message.member.voice.channel, args[0]);
|
let track = await client.player.play(message.member.voice.channel, args[0]);
|
||||||
song.queue.on('end', () => {
|
track.queue.on('end', () => {
|
||||||
message.channel.send('The queue is empty, please add new songs!');
|
message.channel.send('The queue is empty, please add new tracks!');
|
||||||
});
|
});
|
||||||
song.queue.on('songChanged', (oldSong, newSong, skipped, repeatMode) => {
|
track.queue.on('trackChanged', (oldTrack, newTrack, skipped, repeatMode) => {
|
||||||
if(repeatMode){
|
if(repeatMode){
|
||||||
message.channel.send(`Playing ${newSong} again...`);
|
message.channel.send(`Playing ${newTrack} again...`);
|
||||||
} else {
|
} else {
|
||||||
message.channel.send(`Now playing ${newSong}...`);
|
message.channel.send(`Now playing ${newTrack}...`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -492,12 +492,12 @@ client.on('message', (message) => {
|
||||||
const command = args.shift().toLowerCase();
|
const command = args.shift().toLowerCase();
|
||||||
|
|
||||||
// Error 1:
|
// Error 1:
|
||||||
// Song not found
|
// Track not found
|
||||||
if(command === 'play'){
|
if(command === 'play'){
|
||||||
client.player.play(message.member.voice.channel, args[0]).then((song) => {
|
client.player.play(message.member.voice.channel, args[0]).then((track) => {
|
||||||
message.channel.send(`Currently playing ${song.name}!`);
|
message.channel.send(`Currently playing ${track.name}!`);
|
||||||
}).catch(() => {
|
}).catch(() => {
|
||||||
message.channel.send(`No song found for ${args[0]}`);
|
message.channel.send(`No track found for ${args[0]}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -505,7 +505,7 @@ client.on('message', (message) => {
|
||||||
// Not playing
|
// Not playing
|
||||||
if(command === 'queue'){
|
if(command === 'queue'){
|
||||||
let playing = client.player.isPlaying(message.guild.id);
|
let playing = client.player.isPlaying(message.guild.id);
|
||||||
if(!playing) return message.channel.send(':x: No songs currently playing!');
|
if(!playing) return message.channel.send(':x: No tracks currently playing!');
|
||||||
// you are sure it works:
|
// you are sure it works:
|
||||||
client.player.getQueue(message.guild.id);
|
client.player.getQueue(message.guild.id);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue