在discordgo上意图(Intents)无法工作,我该如何修复它?

huangapple go评论82阅读模式
英文:

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)
	}
}

huangapple
  • 本文由 发表于 2022年2月1日 04:03:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/70932165.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定