I've programmed about 5 different Discord bots, and to be totally honest, my implementations continue to evolve and change. As it's all custom coding. Especially with the new library updates that have been implemented that I use.
But I will be able to give you a rough rundown of how it works.
I primarily use node.js and discord.js. But it is possible to program a Discord bot in C#/.NET, Go, C++, Perl, Python. So if you know one of those languages already, I suggest you stick to that language to make it easier.
To stream the audio to a voice channel, a few things are needed:
An audio stream obviously.
A channel to stream into.
An intermediate program that pushes the audio to the Discord bot program (discord.js uses ffmpeg for allot of things for example).
A discord bot.
I assume you don't have problems getting the first 3 things. So the last thing will be the challenge. You can download pre-fab bots on the internet that do stuff for you like play YT links or other stuff and sometimes it's easy to change a few options.
But my code to simply play the audio stream is as follows:
JavaScript:
const streamOptions = {seek: 0, volume: false, fec: true, bitrate: 320, highWaterMark: 24}
const broadcast = client.voice.createBroadcast();
broadcast.play(`{streamlink}`, streamOptions);
for (const connection of client.voice.connections.values()) {
connection.play(broadcast);
}
After that when my bot joins the voice channel, I loop over the broadcasts and then play them back. There is only 1 broadcast running so I feel safe to do this
JavaScript:
voiceChannels.join().then(connection => {
client.voice.broadcasts.forEach(broadcast => {
connection.play(broadcast, streamOptions);
})
})
https://discordjs.guide/voice/voice-broadcasts.html#example-usage Here is some more explanations about what is shown here. But this is about all you need if you've got the rest of the bot setup already