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
d.js toolkit
d.js toolkit9mo ago
- 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
AlexDiego123
AlexDiego1239mo ago
discord.js version: v14.13.0 node.js version: v20.9.0
duck
duck9mo ago
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
AlexDiego123
AlexDiego1239mo ago
so i have to do this?
const stream = connection.receiver.subscribe(userid)

const resource = createAudioResource(stream, {
inputType: StreamType.Opus
});

player.play(resource)
const stream = connection.receiver.subscribe(userid)

const resource = createAudioResource(stream, {
inputType: StreamType.Opus
});

player.play(resource)
duck
duck9mo ago
yes
AlexDiego123
AlexDiego1239mo ago
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:
connection.receiver.subscribe(userid, {
end: 'manual'
});
connection.receiver.subscribe(userid, {
end: 'manual'
});
duck
duck9mo ago
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:Interface
AlexDiego123
AlexDiego1239mo ago
can 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 nothing
duck
duck9mo ago
the end option should be an object of its own with at least the behavior property
AlexDiego123
AlexDiego1239mo ago
end: {
behavior: EndBehaviorType.Manual
}
end: {
behavior: EndBehaviorType.Manual
}
is this ok?
duck
duck9mo ago
yes
AlexDiego123
AlexDiego1239mo ago
ok and in maxMissedFrames is there a way to set it to infinite
duck
duck9mo ago
you realistically shouldn't in the event the receive stream has issues you'll want playback to timeout eventually
AlexDiego123
AlexDiego1239mo ago
ok ok i got it working, thanks for helping me!