Update VoiceCall.md

This commit is contained in:
Cinnamon 2022-09-11 10:06:34 +07:00 committed by GitHub
parent 04938bc4a5
commit 6d92f70bb6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -66,7 +66,7 @@ let i = setInterval(() => {
```js ```js
/* Copyright aiko-chan-ai @2022. All rights reserved. */ /* Copyright aiko-chan-ai @2022. All rights reserved. */
const DjsVoice = require('@discordjs/voice'); const DjsVoice = require('@discordjs/voice');
const Discord = require('discord.js-selfbot-v13'); const Discord = require('./mymodule/src/index.js'); // require('discord.js-selfbot-v13');
const playDL = require('play-dl'); const playDL = require('play-dl');
const EventEmitter = require('events'); const EventEmitter = require('events');
const Event = { const Event = {
@ -359,22 +359,25 @@ class Player extends EventEmitter {
if (!this._currentResourceAudio) throw new Error('No current resource audio'); if (!this._currentResourceAudio) throw new Error('No current resource audio');
this._stop(false, this.options.leaveOnStop); this._stop(false, this.options.leaveOnStop);
} }
_reset(){
this._currentTime = 0;
this._currentResourceAudio = null;
this._playingTime = 0;
this.isPlaying = false;
this._player.stop();
}
_stop(finish = false, force = false) { _stop(finish = false, force = false) {
if (!this._currentResourceAudio) return; if (!this._currentResourceAudio) return;
this._queue.reset(); this._queue.reset();
this._previousSongs.reset(); this._previousSongs.reset();
this._timeoutEmpty = undefined; this._timeoutEmpty = undefined;
this._player.stop(); this._reset();
this._currentTime = 0; if (force || finish && this.options.leaveOnFinish) this.currentConnection?.destroy();
this._currentResourceAudio = null;
this._playingTime = 0;
this.isPlaying = false;
this.channel = null; this.channel = null;
this.guild = null; this.guild = null;
this.song = null; this.song = null;
this.volume = 100; this.volume = 100;
this.loopMode = 0; this.loopMode = 0;
if (force || !finish && this.options.leaveOnStop || finish && this.options.leaveOnFinish) this.currentConnection?.destroy();
this.message = null; this.message = null;
} }
skip() { skip() {
@ -403,6 +406,9 @@ class Player extends EventEmitter {
} }
async previous() { async previous() {
if (!this._previousSongs.length) throw new Error('No previous songs'); if (!this._previousSongs.length) throw new Error('No previous songs');
const currentSong = this.song;
// add to queue
this._queue.enqueue(currentSong);
const previousSong = this._previousSongs.pop(); const previousSong = this._previousSongs.pop();
this.song = previousSong; this.song = previousSong;
await this.createStream(this.song.url); await this.createStream(this.song.url);
@ -508,8 +514,8 @@ class Player extends EventEmitter {
_privateEvent() { _privateEvent() {
this.on('next_song', async () => { this.on('next_song', async () => {
await this._skip().catch(() => { await this._skip().catch(() => {
this.emit(Event.FINISH, this.message); if (this.message) this.emit(Event.FINISH, this.message);
this._stop(true); this._reset();
}); });
}); });
} }