From 0d427cab71afde34186c5cac2a619638db56f650 Mon Sep 17 00:00:00 2001 From: diamondburned Date: Mon, 30 Nov 2020 16:42:26 -0800 Subject: [PATCH] Voice: Allow New without intents --- voice/voice.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/voice/voice.go b/voice/voice.go index f108f8e..ead9093 100644 --- a/voice/voice.go +++ b/voice/voice.go @@ -56,16 +56,21 @@ func NewVoiceFromToken(token string) (*Voice, error) { // This function will add the Guilds and GuildVoiceStates intents into the state // in order to receive the needed events. func NewVoice(s *state.State) *Voice { + // Register the voice intents. + s.Gateway.AddIntents(gateway.IntentGuilds) + s.Gateway.AddIntents(gateway.IntentGuildVoiceStates) + return NewVoiceWithoutIntents(s) +} + +// NewVoice creates a new Voice repository wrapped around a state without +// modifying the given Gateway to add intents. +func NewVoiceWithoutIntents(s *state.State) *Voice { v := &Voice{ State: s, sessions: make(map[discord.GuildID]*Session), ErrorLog: defaultErrorHandler, } - // Register the voice intents. - s.Gateway.AddIntents(gateway.IntentGuilds) - s.Gateway.AddIntents(gateway.IntentGuildVoiceStates) - // Add the required event handlers to the session. v.closers = []func(){ s.AddHandler(v.onVoiceStateUpdate),