-
Notifications
You must be signed in to change notification settings - Fork 877
Description
Hi There! Im not sure if im just doing something wrong, but I cannot get ChannelVoiceJoin to work, I just get a timeout waiting for voice , and it seems to mess with the websocket in general, because the bot seems to drop and reconnect constantly after that (it shows as going offline and online in discord)
here is the handler function I am using to try and connect to a voice channel:
func joinHandler(session *discordgo.Session, interaction *discordgo.InteractionCreate) (err error) {
// Sending text response
returnString := "Attempting to join users Voice Channel..."
response := &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: returnString,
},
}
err = session.InteractionRespond(interaction.Interaction, response)
if err != nil {
log.Printf("Error while responding to interaction: %s\n", err)
}
// Find what VC to join
var guildID string
var channelID string
// Find the channel the message came from
channel, err := session.State.Channel(interaction.ChannelID)
if err != nil {
log.Printf("Couldnt find channel for join command: %s\n", err)
}
// Find Guild channel belongs to
guild, err := session.State.Guild(channel.GuildID)
if err != nil {
log.Printf("Couldnt find matching guild for channel: %s\n", err)
}
// Look at VCs and find user
for _, voiceStatus := range guild.VoiceStates {
voiceID := voiceStatus.UserID
interactionID := interaction.Member.User.ID
if voiceID == interactionID {
fmt.Printf("Found user %s in channel %s\n", interaction.Member.User.Username, voiceStatus.ChannelID)
channelID = voiceStatus.ChannelID
}
}
if channelID == "" {
log.Println("Couldnt find user who ran join")
}
// Join the voice channel
log.Printf("Attempting to join voice channel\n")
voiceSession, err := session.ChannelVoiceJoin(guildID, channelID, false, true)
if err != nil {
log.Printf("Error while attempting to join server: %s\n", err)
}
voiceSession.Speaking(true)
time.Sleep(10 * time.Second)
voiceSession.Disconnect()
return nil
}Here is the source repo if you want a comprehensive look: https://github.com/dakota-marshall/stankbot/blob/main/main.go
Ive tried statically setting the Guild ID and the Voice Channel ID from the values inside discord, just to make sure I wasnt pulling incorrect values, and I just get the timeout.
Ive tried using some of the examples, but I think those are fairly out of date or something as I cant even get those to recognize commands.
Let me know if there is anything else you need from me!