Relay audio from a channel to another
Hi, i'm creating a bot with discord.js v14 that has to relay the voice of an user in a channel to another channel in another server, i can't figure out how to play the stream from connection.receiver.subscribe(userID).
14 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 OPdiscord.js version:
v14.13.0
node.js version: v20.9.0
it'd be similar to how you'd play anything else
you need to create an audio resource from the stream and play the resource with an audio player that your voice connection is subscribed to
you'd just want to specify
StreamType.Opus
for the inputType
option of createAudioResource
so i have to do this?
yes
ok it works but if you stop talking and then start again the bot doesn't play the audio
how do i fix this so that it always streams until i stop it?
it said to set the manual mode in the connection.receiver.subscribe but it didn't change anything
i did this:
not sure where you read that
end
or even the behavior type could be a string
the end
option should be an object of its own with at least the behavior
property
the behavior
should be a number for which you can use the EndBehaviorType
enum
beyond this you may also need to specify the maxMissedFrames
behavior when creating your audio player
https://discord.js.org/docs/packages/voice/main/AudioReceiveStreamOptions:Interface
https://discord.js.org/docs/packages/voice/main/CreateAudioPlayerOptions:Interfacecan you write an example for me?
i want it to always stream the user's voice no matter if you're talking or not
btw i realized it wasn't a string and i tried
end: EndBehaviorType.Manual
but still nothingtheend
option should be an object of its own with at least thebehavior
property
is this ok?
yes
ok and in maxMissedFrames is there a way to set it to infinite
you realistically shouldn't
in the event the receive stream has issues you'll want playback to timeout eventually
ok
ok i got it working, thanks for helping me!