Play Audio Resource even when bot isn't in a voice channel
Hi guys, I've created a bot that gets a live feed from a radio station and then outputs the audio into a voice channel (by using a
ReadableStream
object as the input for createAudioResource()
). Whenever there is nobody active in the voice channel, I make the bot leave the channel, and when someone rejoins, the bot also rejoins. Everything works fine except this: when the bot isn't actively in the voice channel, the playback pauses and then resumes at the same point when someone rejoins, rather than playing the latest chunks in the stream. Every second the bot isn't inside the voice channel, its playback basically delays an additional second from being actually live.
Is there an easy way I can get around this? I'm not sure if the solution is JS-based or part of the discord.js library. I saw the noSubscriber: 'play'
flag in createAudioPlayer()
options but this only seems to ontinue playback when the bot is alone in a channel, not when the bot itself isn't in any channel.3 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 OPthis would be better suited to #djs-voice
that being said, the
noSubscriber
behavior is what you would want to use
since AudioPlayer
s aren't dependent on VoiceConnection
s, that should be how you'd achieve this beyond simply stopping playback and resuming when there's a subscribed VoiceConnection
the bot being alone in a channel also should still be considered a valid subscribed connection assuming it's in the Ready
state, so this shouldn't be affected by the noSubscriber
behavior
how have you determined that this is how it behaves?thanks so much for responding! Reading the docs I think you're right, noSubscriber should work. so I guess the issue is somewhere else, is there something wrong with the way I'm setting the flag?
omg that turned out so ugly sorry
oh I'm so dumb I need to pass in
behaviors
as a nested object to make the flag work
my bad solved!!