Music bot reference error

when my bot play youtube video,some youtube video normally played, but the others cannot played.
there is an error in this part.

const dispatcher = queue.connection
.play(stream { type: “opus” })
.on(“finish” , ( ) => {
collector.stop ( );

and log says : ReferenceError: Cannot access ‘collector’ before initialization

what should I do?

As the error says, you’re defining collector, but as you’re defining it, you use that term in const collector = collector.stop ( );

You can’t define something as the definition of it.
(Sorry if it seems too complicated for you)

In particular, I can’t play videos that I uploaded myself, but there are no problems playing videos with high views or famous videos.
Also, the video I uploaded is not private.
Do you know what to do if there is a problem with the code I entered?

Are there any erros in the logs?
If there are, could you send them here to understand what you’re currently facing?

Also, I think playing your videos is not a bot error, but maybe the module cannot either fetch these videos or the YouTube API doesn’t allow to play them, maybe.

This is the error that appears in the log.

As the error says, you’re defining collector , but as you’re defining it, you use that term in const collector = collector.stop ( );
You can’t define something as the definition of it.
(Sorry if it seems too complicated for you)

As I said above…

I think it’s a YouTube api problem. Because I just checked it, the error rate of the api is over 50%. Thank you for answering anyway.

it has nothing to do with the youtube api.
you are defining “collector” and you are using it in its own initialization, before it’s even initialized.

literally:
const thisIsNotInitializedYet = thisIsNotInitializedYet.name

So I changed my code,
removed const,collector
This is the code I fixed.

const dispatcher = queue.connection
.play(stream { type: “opus” })
.on(“finish” , ( ) => {
collector.stop ( );

and etc.

But it still doesn’t play in some videos. If you know the solution, please enter the code.
Thank you for your explanation.

Any Logs errors pop up?

It repeats the same error.
To be exact, there’s a video search result and a bot on the voice channel, but I can’t hear anything.

That’s simple : Collector is not defined. You can’t do const collector = collector.stop() and you can’t do collector.stop().

You need to define collector first, then you can do collector.stop().

I changed the code :
const dispatcher = queue.connection
.play(stream { type: “opus” })
.on(“finish” , ( ) => {
collector.stop ( );

and etc.

But some videos have no problem playing, and this problem only occurs in part of YouTube videos.

Remove the type “opus” part.

I’m sorry, but it doesn’t seem to work.
Otherwise, the module I’m using is ytdl-core-discord, is there any difference from the regular ytdl-core module?

I should use the ytdl-core. Maybe that is the issue.

Can you try to run npm install? Just curious if you’d have the same issue as a few others have

I started to see error like that I’m script earlier, but then I realized that the problem is on Glitch side… Getting out of space even if I made loads of space to work

There’s no problem installing the npm, and I think it was just a module problem.

When I changed the module to ytdl core, it worked normally. Thank you very much for your help.:sob: