From aa9dacfd82daa842784877d6f5cf96d2f9936290 Mon Sep 17 00:00:00 2001 From: Mia Date: Thu, 20 Jul 2023 18:53:23 -0700 Subject: [PATCH 1/2] feat: Add SendRawGatewayMessage function Signed-off-by: Mia --- wsapi.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/wsapi.go b/wsapi.go index 9ef6dd08a..b9f942ef1 100644 --- a/wsapi.go +++ b/wsapi.go @@ -495,6 +495,21 @@ func (s *Session) RequestGuildMembersBatchList(guildIDs []string, userIDs []stri return } +// SendRawGatewayMessage allows for sending raw gateway messages untouched by discordgo. +func (s *Session) SendRawGatewayMessage(data interface{}) (err error) { + s.RLock() + defer s.RUnlock() + if s.wsConn == nil { + return ErrWSNotFound + } + + s.wsMutex.Lock() + err = s.wsConn.WriteJSON(data) + s.wsMutex.Unlock() + + return err +} + func (s *Session) requestGuildMembers(data requestGuildMembersData) (err error) { s.log(LogInformational, "called") From 991c4b67106db08e0ba9a115b03a374013107f22 Mon Sep 17 00:00:00 2001 From: Fedor Lapshin Date: Sun, 7 Jul 2024 22:20:06 +0300 Subject: [PATCH 2/2] apply changes from review --- wsapi.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wsapi.go b/wsapi.go index b9f942ef1..fb6438be6 100644 --- a/wsapi.go +++ b/wsapi.go @@ -495,8 +495,8 @@ func (s *Session) RequestGuildMembersBatchList(guildIDs []string, userIDs []stri return } -// SendRawGatewayMessage allows for sending raw gateway messages untouched by discordgo. -func (s *Session) SendRawGatewayMessage(data interface{}) (err error) { +// GatewayWriteStruct allows for sending raw gateway structs over the gateway. +func (s *Session) GatewayWriteStruct(data interface{}) (err error) { s.RLock() defer s.RUnlock() if s.wsConn == nil {