From 07dda983e47dca4b82e816c52a290b4ce48b6a4f Mon Sep 17 00:00:00 2001 From: fakelag <35497506+fakelag@users.noreply.github.com> Date: Sun, 18 Feb 2024 19:44:10 +0200 Subject: [PATCH] Get guilds from state for voice connections --- discordplayer/interfaces/discordsessioninterface.go | 10 +++++----- discordplayer/voiceworker.go | 4 ++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/discordplayer/interfaces/discordsessioninterface.go b/discordplayer/interfaces/discordsessioninterface.go index cd36870..8e58c50 100644 --- a/discordplayer/interfaces/discordsessioninterface.go +++ b/discordplayer/interfaces/discordsessioninterface.go @@ -25,13 +25,13 @@ func (dds *DefaultDiscordSession) ChannelVoiceJoin(gID string, cID string, mute } func (dds *DefaultDiscordSession) Guild(gID string) (guild DiscordGuild, err error) { - g, err := dds.session.Guild(gID) - - if err != nil { - return nil, err + for _, guild := range dds.session.State.Guilds { + if guild.ID == gID { + return NewDiscordGuild(guild), nil + } } - return NewDiscordGuild(g), err + return nil, nil } func (dds *DefaultDiscordSession) User(uID string) (user DiscordUser, err error) { diff --git a/discordplayer/voiceworker.go b/discordplayer/voiceworker.go index f958bd8..2c99407 100644 --- a/discordplayer/voiceworker.go +++ b/discordplayer/voiceworker.go @@ -318,6 +318,10 @@ func (dms *DiscordMusicSession) hasNonBotMembersInVoiceChannel(voiceChannelID st return false, err } + if guild == nil { + return false, errors.New("guild not found") + } + voiceStates := guild.GetVoiceStates() hasNonBotMembersInVC := false