Voice provides a package to connect and send/receive voice to/from discord servers. For Discords Docs on voice see here.
To send audio you need to create a voice connection. When using the bot.Client
package you can use client.VoiceManager().CreateConn(guildID)
const (
guildID = 12345
channelID = 12345
)
var client bot.Client
conn := client.VoiceManager().CreateConn(guildID)
err := conn.Open(context.TODO(), channelID, false, false)
// handle err
// send opus frame
conn.Conn().Write(frame)
// close connection
conn.Close()
When using the voice package standalone you should create a voice manager. After this you can call voice.Manager.CreateConn(guildID)
. After this you should send a gateway.OpcodeVoiceStateUpdate
packet to the gateway.