fix(StreamDispatcher): check if resource has ended
This commit is contained in:
parent
edc54bb38a
commit
dd91244e43
2 changed files with 8 additions and 1 deletions
|
@ -19,7 +19,13 @@ client.on("error", console.error);
|
||||||
client.on("warn", console.warn);
|
client.on("warn", console.warn);
|
||||||
|
|
||||||
// instantiate the player
|
// instantiate the player
|
||||||
const player = new Player(client);
|
const player = new Player(client, {
|
||||||
|
ytdlOptions: {
|
||||||
|
headers: {
|
||||||
|
cookie: process.env.YT_COOKIE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
player.on("error", (queue, error) => {
|
player.on("error", (queue, error) => {
|
||||||
console.log(`[${queue.guild.name}] Error emitted from the queue: ${error.message}`);
|
console.log(`[${queue.guild.name}] Error emitted from the queue: ${error.message}`);
|
||||||
|
|
|
@ -184,6 +184,7 @@ class StreamDispatcher extends EventEmitter<VoiceEvents> {
|
||||||
*/
|
*/
|
||||||
async playStream(resource: AudioResource<Track> = this.audioResource) {
|
async playStream(resource: AudioResource<Track> = this.audioResource) {
|
||||||
if (!resource) throw new PlayerError("Audio resource is not available!", ErrorStatusCode.NO_AUDIO_RESOURCE);
|
if (!resource) throw new PlayerError("Audio resource is not available!", ErrorStatusCode.NO_AUDIO_RESOURCE);
|
||||||
|
if (resource.ended) return void this.emit("error", new PlayerError("Cannot play a resource that has already ended.") as unknown as AudioPlayerError);
|
||||||
if (!this.audioResource) this.audioResource = resource;
|
if (!this.audioResource) this.audioResource = resource;
|
||||||
if (this.voiceConnection.state.status !== VoiceConnectionStatus.Ready) {
|
if (this.voiceConnection.state.status !== VoiceConnectionStatus.Ready) {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue