jack3898 / discord-youtube-bot-2

A powerful Discord YouTube Bot.
0 stars 0 forks source link

TypeError: ID for the video resource cannot be found or was not valid. #19

Open NeboCode opened 1 year ago

NeboCode commented 1 year ago

bot | TypeError: ID for the video resource cannot be found or was not valid. bot | at YouTubeVideo.get id [as id] (/home/node/src/classes/modules/YouTubeVideo.ts:72:9) bot | at new YouTubeVideo (/home/node/src/classes/modules/YouTubeVideo.ts:14:48) bot | at Function.fromId (/home/node/src/classes/modules/YouTubeVideo.ts:25:10) bot | at /home/node/src/classes/modules/YouTubeInterface.ts:187:40 bot | at runMicrotasks () bot | at processTicksAndRejections (node:internal/process/task_queues:96:5)

Seems like something is broken in the source code, any fix available?

MalekMohamed commented 1 year ago

I fixed it by reversing the condition in src\classes\modules\YouTubeInterface.ts line 190. you should be able to see this condition if (!audioResource) throw Error('Could not resolve the audio resource from YouTube.'); you can just revert the condition, the try body should be something like this.


if (audioResource) {
  this.currentResource = audioResource;
  this.currentResource.volume?.setVolume(this.audioVolume);
  this.player.play(this.currentResource);
  this.player.once('error', () => {
      throw Error('Bad audio resource, cannot continue.');
  });
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
 // @ts-ignore Incorrect type error: Argument of type '"stateChange"' is not assignable to parameter of type 
 'AudioPlayerStatus.Idle'.
  this.player.on('stateChange', async (oldState: AudioPlayerState, newState: AudioPlayerState) => {
      if (oldState.status === 'playing' && newState.status === 'idle') {
          const toResolve = await this.handleFinish();
          resolve(toResolve);
      }
  });
}