1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-12-01 03:03:48 +00:00
arikawa/voice/session_example_test.go

70 lines
1.3 KiB
Go
Raw Normal View History

package voice_test
import (
2021-06-10 23:48:32 +00:00
"context"
"io"
"log"
"testing"
2021-06-02 02:53:19 +00:00
"github.com/diamondburned/arikawa/v3/discord"
"github.com/diamondburned/arikawa/v3/internal/testenv"
"github.com/diamondburned/arikawa/v3/state"
"github.com/diamondburned/arikawa/v3/voice"
)
var (
token string
channelID discord.ChannelID
)
func init() {
e, err := testenv.GetEnv()
if err == nil {
token = e.BotToken
channelID = e.VoiceChID
}
}
// pseudo function for example
func writeOpusInto(w io.Writer) {}
// make godoc not show the full file
func TestNoop(t *testing.T) {
t.Skip("noop")
}
func ExampleSession() {
s, err := state.New("Bot " + token)
if err != nil {
log.Fatalln("failed to make state:", err)
}
// This is required for bots.
voice.AddIntents(s.Gateway)
2021-06-10 23:48:32 +00:00
if err := s.Open(context.TODO()); err != nil {
log.Fatalln("failed to open gateway:", err)
}
defer s.Close()
c, err := s.Channel(channelID)
if err != nil {
log.Fatalln("failed to get channel:", err)
}
v, err := voice.NewSession(s)
if err != nil {
log.Fatalln("failed to create voice session:", err)
}
if err := v.JoinChannel(c.GuildID, c.ID, false, false); err != nil {
log.Fatalln("failed to join voice channel:", err)
}
defer v.Leave()
// Start writing Opus frames.
for {
writeOpusInto(v)
}
}