🥅 Add video unavailable error

This commit is contained in:
Androz2091 2021-02-20 15:59:55 +01:00
parent 35fd4e663b
commit d79c39949d
3 changed files with 12 additions and 3 deletions

View file

@ -161,6 +161,9 @@ client.player
case 'LiveVideo': case 'LiveVideo':
message.channel.send('YouTube lives are not supported!') message.channel.send('YouTube lives are not supported!')
break; break;
case 'VideoUnavailable':
message.channel.send('This YouTube video is not available!');
break;
default: default:
message.channel.send(`Something went wrong... Error: ${error}`) message.channel.send(`Something went wrong... Error: ${error}`)
} }

View file

@ -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(() => { setTimeout(() => {
if (queue.stream) queue.stream.destroy() if (queue.stream) queue.stream.destroy()
@ -1254,7 +1260,7 @@ module.exports = Player
/** /**
* Emitted when an error is triggered * Emitted when an error is triggered
* @event Player#error * @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 * @param {Discord.Message} message
*/ */

2
typings/index.d.ts vendored
View file

@ -107,7 +107,7 @@ declare module 'discord-player' {
requestedBy: User; requestedBy: User;
} }
type Playlist = YTSRPlaylist & CustomPlaylist; type Playlist = YTSRPlaylist & CustomPlaylist;
type PlayerError = 'NotConnected' | 'UnableToJoin' | 'NotPlaying' | 'LiveVideo' | 'ParseError'; type PlayerError = 'NotConnected' | 'UnableToJoin' | 'NotPlaying' | 'LiveVideo' | 'ParseError' | 'VideoUnavailable';
interface PlayerEvents { interface PlayerEvents {
searchResults: [Message, string, Track[]]; searchResults: [Message, string, Track[]];
searchInvalidResponse: [Message, string, Track[], string, MessageCollector]; searchInvalidResponse: [Message, string, Track[], string, MessageCollector];