英文:
Intents not working on discordgo, how do i fix it
问题
dg.Identify.Intents = discordgo.MakeIntent(discordgo.IntentsAll)
err = dg.Open()
if err != nil {
panic(err)
}
这段代码无法正常工作,我想要通过使用公会ID来获取我创建的公会中的成员,就像这样(mee.dg是一个Discord会话):
func (mee *Meeee) CheckCurrentUserList() {
guild, err := mee.dg.Guild(config.Manager.MeeeeCredentials.Guild.Id)
if err != nil {
panic(err)
}
log.Printf("%v", guild.Name)
log.Printf("%v", guild.Channels)
for _, member := range guild.Members {
log.Printf("user - name: %v, id: %v", member.User.Username, member.User.ID)
}
}
英文:
dg.Identify.Intents = discordgo.MakeIntent(discordgo.IntentsAll)
err = dg.Open()
if err != nil {
panic(err)
}
it doesnt work, i want to pull members in the guild which one i created with using guild id, like this (mee.dg is a discord session)
func (mee *Meeee) CheckCurrentUserList() {
guild, err := mee.dg.Guild(config.Manager.MeeeeCredentials.Guild.Id)
if err != nil {
panic(err)
}
log.Printf("%v", guild.Name)
log.Printf("%v", guild.Channels)
for _, member := range guild.Members {
log.Printf("user - name: %v, id: %v", member.User.Username, member.User.ID)
}
}
答案1
得分: 0
实际上,我遇到的问题与意图无关。 Discordgo结构中的公会结构体具有一个成员字段,这让我产生了误导。为了获取公会成员,还需要进行另一个HTTP请求,所以我必须使用"GuildMembers(parameters)"函数。
func (mee *Meeee) CheckCurrentUserList() {
members, err := mee.dg.GuildMembers(config.Manager.MeeeeCredentials.Guild.Id, "", 100)
if err != nil {
panic(err)
}
for _, member := range members {
log.Printf("用户 - 名称:%v,ID:%v", member.User.Username, member.User.ID)
}
}
英文:
actually the problem i faced had nothing to do with intents. The fact that the guild struct in Discordgo structs has a member field misled me. Another http request is being made to reach the Guild Members, so I had to use the "GuildMembers(parameters)" function.
func (mee *Meeee) CheckCurrentUserList() {
members, err := mee.dg.GuildMembers(config.Manager.MeeeeCredentials.Guild.Id, "", 100)
if err != nil {
panic(err)
}
for _, member := range members {
log.Printf("user - name: %v, id: %v", member.User.Username, member.User.ID)
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论