From d79c39949d381e7c2087182fe70703a1e15e2096 Mon Sep 17 00:00:00 2001 From: Androz2091 Date: Sat, 20 Feb 2021 15:59:55 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=85=20Add=20video=20unavailable=20erro?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 3 +++ src/Player.js | 10 ++++++++-- typings/index.d.ts | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a8fc116..80c4e3e 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,9 @@ client.player case 'LiveVideo': message.channel.send('YouTube lives are not supported!') break; + case 'VideoUnavailable': + message.channel.send('This YouTube video is not available!'); + break; default: message.channel.send(`Something went wrong... Error: ${error}`) } diff --git a/src/Player.js b/src/Player.js index 21150f6..c9f8a41 100644 --- a/src/Player.js +++ b/src/Player.js @@ -1094,7 +1094,13 @@ class Player extends EventEmitter { }) } - newStream.on('error', (error) => this.emit('error', error, queue.firstMessage)) + newStream.on('error', (error) => { + if (error.message === 'Video unavailable') { + this.emit('error', 'VideoUnavailable', queue.firstMessage) + } else { + this.emit('error', error, queue.firstMessage) + } + }) setTimeout(() => { if (queue.stream) queue.stream.destroy() @@ -1254,7 +1260,7 @@ module.exports = Player /** * Emitted when an error is triggered * @event Player#error - * @param {string} error It can be `NotConnected`, `UnableToJoin`, `NotPlaying`, `ParseError` or `LiveVideo`. + * @param {string} error It can be `NotConnected`, `UnableToJoin`, `NotPlaying`, `ParseError`, `LiveVideo` or `VideoUnavailable`. * @param {Discord.Message} message */ diff --git a/typings/index.d.ts b/typings/index.d.ts index 1879c70..2b97d13 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -107,7 +107,7 @@ declare module 'discord-player' { requestedBy: User; } type Playlist = YTSRPlaylist & CustomPlaylist; - type PlayerError = 'NotConnected' | 'UnableToJoin' | 'NotPlaying' | 'LiveVideo' | 'ParseError'; + type PlayerError = 'NotConnected' | 'UnableToJoin' | 'NotPlaying' | 'LiveVideo' | 'ParseError' | 'VideoUnavailable'; interface PlayerEvents { searchResults: [Message, string, Track[]]; searchInvalidResponse: [Message, string, Track[], string, MessageCollector];