55 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
- ✅
Marked as resolved by OP@ShompiFlen
okay so can you show me your package.json file
also share your index.js file so i can see the code in its entirety
hide any tokens
you are missing some dependencies
But my index consists of hundreds of lines
then share the section of your code where you start using voice related functions
also read this part https://discordjs.guide/voice/#barebones
there are some extra but optional dependencies that you should try installing, for example
@discordjs/opus
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
im guessing you installed ffmpeg and added it to the path too right?
yes
Uploading now
libsodium-wrappers is one that i would recommend installing too, although you may have issues installing that one, but give it a try
so at this point, what does the bot do and what what it doesn't?, does it connect to the voice channel?
I got an error downloading the sodium module and could not download it
what does the error say?
Yes, it connects to the audio channel, but it doesn't play anything, it just stops and waits
The libsodium-wrappers module downloaded without any problems
ah
okay good
so as the guide says, you should've at least have one of the encryption libraries installed to use voice
in this case you installed libsodium-wrappers
so try to play music now
My pc is bad sorry
okay we will need to do some debugging here
i need you to paste these pieces of code in your script
then test your bot again
disconnect it first
Trying right away
then run it
just paste them right below your player.play call
wrote very long articles 😅
try to find the beginning of it and send it
like the first 10 lines or something
or a screenshot of the entire terminal
okay and how it ends?
It seemed to go on forever, after 5 seconds i closed it myself from the terminal
alright, the bot is connecting to voice succesfully
you are having trouble with the audio resource
how long is this mp3?
7 sec
there is a slight chance of the audioresource ending before your bot is ready to play it
so lets try the following
But how can i prevent it?
thats where im going at
listen to this event
inside there, call player.play(resource)
this will start playing the resource once your bot is connected and ready to transmit audio
not before
Is it right to do it this way?
sure, but preferably you would put that at the end
but it should work either way
make sure to import VoiceConnectionStatus
Isn't that right import?
yes
It gave this warning and the bot didn't say anything
connection.subscribe(player); what does this saturation do?
Ohh reaally??
when i put this line inside ready, it worked
ohhhh
pretty sure this is the thing that makes the audio player play things through the connection
yea it worked because your mp3 is too short, it was probably ending before your bot was ready to transmit audio
Thank you very much for your
the memory leak thing tho not sure, you should put some other checks in your code so this code doesn't run too frequently
you can also change that bit for this
await entersState(connection, VoiceConnectionStatus.Ready, 20_000)
you have to make the event async though to use await
this is the promisified version of connection.on(VoiceConnectionStatus.Ready, () )
, you need to pass it the connection, the state you are waiting for, and how long to wait for it or throw an error otherwiseshould I delete this part in ss and write await entersState(connection, VoiceConnectionStatus.Ready, 20_000)
or only i delete line 60
you can if you want but its not really necessary if you are okay working with that. You would also have to handle the promise rejection of it in case your bot can't reach the ready state
okay so if you want to replace that for the promise, you have to delete line 60 and 63
then use this
await entersState(connection, VoiceConnectionStatus.Ready, 20_000)
and below this you call player.play and connection.subscribeI should import entersState, right?
Yes
Your code right now is kind of unsafe
you should change this at some point and make your bot connect to the voice channel through a command
not when it receives a VoiceStateUpdate
thats probably why you got the memory leak warning
School starts in 6 hours, I have to go to bed. Thank you very much for your help
np
I did this command in the past when i was trying this system, i guess it's your night too. Good night, i am going to bed 🛏️
Thanks again for your help :)
Should i press this button?
if your issue is resolved and you dont have any more questions then yes, feel free to resolve this post