Compare commits

..

1 Commits

Author SHA1 Message Date
748addcd2b
adding message method to join vc's 2025-08-17 20:52:35 -04:00
2 changed files with 34 additions and 0 deletions

28
bolt.go
View File

@ -1,6 +1,7 @@
package bolt
import (
"errors"
"fmt"
"log"
"os"
@ -43,6 +44,7 @@ type Bolt interface {
getRemainingTimeout(timeout time.Time) string
roleCheck(guild string, roles []string, s *dg.Session, run Command) (bool, error)
timeoutCheck(msgID, channelID, guildID string, s *dg.Session, run Command) (bool, error)
joinUserVoice(guild, user string, s *dg.Session) (*dg.VoiceConnection, error)
}
// create a new bolt interface
@ -328,3 +330,29 @@ func (b *bolt) timeoutCheck(msgID, channelID, guildID string, s *dg.Session, run
return true, nil
}
func (b *bolt) joinUserVoice(guild, user string, s *dg.Session) (*dg.VoiceConnection, error) {
g, err := s.State.Guild(guild)
if err != nil {
return nil, err
}
var chanID string
for _, x := range g.VoiceStates {
if user == x.UserID {
chanID = x.ChannelID
}
}
if chanID == "" {
return nil, errors.New("user is not in a voice channel")
}
//joining voice channel: false = not muted, true = deafened
dgv, err := s.ChannelVoiceJoin(guild, chanID, false, true)
if err != nil {
return nil, err
}
return dgv, nil
}

View File

@ -96,3 +96,9 @@ func (m *Message) Respond(res string) error {
_, err := m.sesh.ChannelMessageSendComplex(m.channelID, rep)
return err
}
// joins the message author's voice channel. Returns the voice connection object, this connection must be cleaned
// up by the client to prevent issues
func (m *Message) JoinVoiceChannel() (*dg.VoiceConnection, error) {
return m.sesh.joinUserVoice(m.serverID, m.ID, m.sesh.Session)
}