Replies: 4 comments 2 replies
-
You may want to wait for the |
Beta Was this translation helpful? Give feedback.
-
@Nv7-GitHub thanks for the response. I've activated the privileged, now my Bot has that, and kicked the boy and made it join again. And my code is the following now package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"github.com/bwmarrin/discordgo"
)
func ready(s *discordgo.Session, event *discordgo.Ready) {
fmt.Println("Ready")
//channel, err := session.State.Channel("YOUR_CHANNEL_ID")
channel, err := s.Channel("YOUR_CHANNEL_ID")
if err != nil {
fmt.Println(err)
} else {
fmt.Println(channel.Name)
fmt.Println(channel.Members)
}
}
func main() {
session, err := discordgo.New(fmt.Sprintf("Bot %s", "BOT_TOKEN"))
if err != nil {
fmt.Println("Error creating Discord session,", err)
return
}
session.AddHandler(ready)
session.Identify.Intents = discordgo.IntentsGuildMembers
err = session.Open()
if err != nil {
fmt.Println("Error opening connection,", err)
return
}
// Wait for closing signal
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
session.Close()
} But I still get an empty slice when I'm in the
I'm pretty sure it's some sort of permissions problem, but I can't figure out which or where to set it. |
Beta Was this translation helpful? Give feedback.
-
If you look at the documentation, it has // All thread members. State channels only.
Members []*ThreadMember `json:"-"` Are you getting it from the state? |
Beta Was this translation helpful? Give feedback.
-
Because it was not clear, I did a lot of digging and finally answered this question. Check it out over here. Here is the example code I wrote up to see how it works. package main
import (
"fmt"
"time"
"github.com/bwmarrin/discordgo"
)
func testCommandHandler(s *discordgo.Session, i *discordgo.InteractionCreate) {
guild, err := s.State.Guild(i.GuildID)
if err != nil {
panic(err)
}
if err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Flags: discordgo.MessageFlagsEphemeral,
Content: fmt.Sprintf("just a test: %d", len(guild.VoiceStates)),
},
}); err != nil {
panic(err)
}
}
func startBot() {
fmt.Println("starting new discord bot")
b, err := discordgo.New("Bot secret-token")
if err != nil {
panic(err)
}
b.Identify.Intents = discordgo.IntentsAll
b.AddHandler(testCommandHandler)
if err := b.Open(); err != nil {
panic(err)
}
if _, err := b.ApplicationCommandCreate("app-id", "guild-id", &discordgo.ApplicationCommand{
Name: "test",
Description: "Get the number of members in all voice channel",
}); err != nil {
panic(err)
}
}
func main() {
go startBot()
for {
fmt.Println("running")
time.Sleep(10 * time.Second)
}
} |
Beta Was this translation helpful? Give feedback.
-
Question
How can I get a list of users given a channel id?
I'm trying to make a command that shuffles the list of connected users in a voice channel.
But I'm having trouble getting the list.
I have tried
Creating a new discord server.
Inviting my bot with all permissions.
Joining the General voice channel.
Running the following code, it recognizes the channel, but it gives me an empty array, like so:
And if I use the commented code, since in some places it says that I should access some data throw the State struct, it gives me an error
state cache not found
Beta Was this translation helpful? Give feedback.
All reactions