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];