1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-27 17:23:00 +00:00

voice: Example should use JoinChannelAndSpeak

This commit is contained in:
diamondburned 2022-01-18 18:22:27 -08:00
parent 2d3bf2974a
commit 85619b2976
No known key found for this signature in database
GPG key ID: D78C4471CE776659

View file

@ -4,6 +4,8 @@ import (
"context" "context"
"io" "io"
"log" "log"
"os"
"os/signal"
"testing" "testing"
"github.com/diamondburned/arikawa/v3/discord" "github.com/diamondburned/arikawa/v3/discord"
@ -34,12 +36,15 @@ func TestNoop(t *testing.T) {
} }
func ExampleSession() { func ExampleSession() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
s := state.New("Bot " + token) s := state.New("Bot " + token)
// This is required for bots. // This is required for bots.
voice.AddIntents(s) voice.AddIntents(s)
if err := s.Open(context.TODO()); err != nil { if err := s.Open(ctx); err != nil {
log.Fatalln("failed to open gateway:", err) log.Fatalln("failed to open gateway:", err)
} }
defer s.Close() defer s.Close()
@ -49,10 +54,10 @@ func ExampleSession() {
log.Fatalln("failed to create voice session:", err) log.Fatalln("failed to create voice session:", err)
} }
if err := v.JoinChannel(context.TODO(), channelID, false, false); err != nil { if err := v.JoinChannelAndSpeak(ctx, channelID, false, false); err != nil {
log.Fatalln("failed to join voice channel:", err) log.Fatalln("failed to join voice channel:", err)
} }
defer v.Leave(context.TODO()) defer v.Leave(ctx)
// Start writing Opus frames. // Start writing Opus frames.
for { for {