docs(VoiceCall): Update music lib

This commit is contained in:
March 7th 2022-08-16 18:47:23 +07:00
parent bfad5d4187
commit 75c8edb26b

View File

@ -159,6 +159,7 @@ class Player extends EventEmitter {
this.isPlaying = false;
this.volume = 100;
this.loopMode = 0;
this.message = undefined;
this._timeoutEmpty = undefined;
this._player = DjsVoice.createAudioPlayer({
behaviors: {
@ -252,6 +253,7 @@ class Player extends EventEmitter {
}
}
this.guild = channel.guild;
this.message = message;
if (typeof query !== 'string') throw new Error(`Invalid query type (Required: string, got: ${typeof query})`);
const result = await this.search(message, query);
if (result.length < 1) {
@ -371,6 +373,7 @@ class Player extends EventEmitter {
this.song = null;
this.volume = 100;
if (force || !finish && this.options.leaveOnStop || finish && this.options.leaveOnFinish) this.currentConnection?.destroy();
this.message = null;
}
skip() {
this._skip();
@ -453,14 +456,14 @@ class Player extends EventEmitter {
}
if (newState.id == this.client.user.id && oldState.channel?.members?.has(this.client.user.id) && !newState.channel?.members?.has(this.client.user.id)) {
this._stop();
this.emit(Event.LEAVE_VC);
this.emit(Event.LEAVE_VC, this.message);
}
if (newState.channel?.members?.has(this.client.user.id) && !newState.channel?.members?.filter(m => m.id != this.client.user.id && !m.bot).size) {
// empty
if (this.options.leaveOnEmpty && !this._timeoutEmpty) {
this._timeoutEmpty = setTimeout(() => {
this._stop(false, true);
this.emit(Event.EMPTY);
this.emit(Event.EMPTY, this.message);
}, this.options.emptyCooldown);
}
}
@ -476,7 +479,7 @@ class Player extends EventEmitter {
if (this.options.leaveOnEmpty && !this._timeoutEmpty) {
this._timeoutEmpty = setTimeout(() => {
this._stop(false, true);
this.emit(Event.EMPTY);
this.emit(Event.EMPTY, this.message);
}, this.options.emptyCooldown);
}
}
@ -503,7 +506,7 @@ class Player extends EventEmitter {
_privateEvent() {
this.on('next_song', async () => {
await this._skip().catch(() => {
this.emit(Event.FINISH);
this.emit(Event.FINISH, this.message);
this._stop(true);
});
});
@ -541,22 +544,22 @@ const player = new Player(client, options);
player
.on('playSong', song => {
console.log(`Now playing: ${song.title}`);
player.message.channel.send(`Now playing: ${song.title}`);
})
.on('addSong', song => {
console.log(`Added: ${song.title}`);
player.message.channel.send(`Added: ${song.title}`);
})
.on('addPlaylist', playlist => {
console.log(`Added Playlist: ${playlist.title}`);
player.message.channel.send(`Added Playlist: ${playlist.title}`);
})
.on('disconnect', () => {
console.log('Disconnected from voice channel.');
.on('disconnect', (message) => {
message.channel.send('Disconnected from voice channel.');
})
.on('finish', () => {
console.log('finish.');
.on('finish', (message) => {
message.channel.send('Finished playing.');
})
.on('empty', () => {
console.log('empty voice channel.');
.on('empty', (message) => {
message.channel.send('The queue is empty.');
})
.on('error', error => {
console.log('Music error', error);