-
Notifications
You must be signed in to change notification settings - Fork 780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(*Session).State is broken in all versions after 0.20.3 #812
Comments
Are you using intents? If so, what intents are you requesting? |
Well... I'm not aware of whether I'm using intents or not, because none of my codes explicitly request any intent. // Open shards sessions and add event handlers to them.
func (d *Discord) Open(handlers ...interface{}) error {
d.mu.Lock()
defer d.mu.Unlock()
// Get Gateway Bot.
gateway, err := discordgo.New("Bot " + d.botToken)
if err != nil {
return err
}
st, err := gateway.GatewayBot()
if err != nil {
return err
}
// Shard into sessions.
d.shards = make([]*discordgo.Session, st.Shards)
for i := 0; i < st.Shards; i++ {
d.shards[i], err = discordgo.New("Bot " + d.botToken)
if err != nil {
return err
}
d.shards[i].ShardID = i
d.shards[i].ShardCount = st.Shards
d.shards[i].StateEnabled = true // just in case
}
// Add handlers.
for _, sess := range d.shards {
for _, handler := range handlers {
sess.AddHandler(handler)
}
}
var errOpen error
{ // Open ws connections.
wg := sync.WaitGroup{}
for _, sess := range d.shards {
wg.Add(1)
go func(sess *discordgo.Session) {
if err := sess.Open(); err != nil {
errOpen = err
}
sess.StateEnabled = true // just in case
wg.Done()
}(sess)
}
wg.Wait()
}
// Close if fail.
if errOpen != nil {
wg := sync.WaitGroup{}
for _, sess := range d.shards {
wg.Add(1)
go func(sess *discordgo.Session) {
_ = sess.Close()
wg.Done()
}(sess)
}
wg.Wait()
}
return errOpen
} |
It's expected that this code will not work for fetching and caching members. This was described in the release notes for v0.21, as well as the FAQ. |
Okay, so I went to https://discord.com/developers/applications/ , ticked both sess.Identify.Intents = discordgo.MakeIntent(discordgo.IntentsAllWithoutPrivileged | discordgo.IntentsGuildPresences | discordgo.IntentsGuildMembers) And it's working again as usual in the lastest current |
I've been using discordgo for months, and these state caches became all empty since release of
v0.21.1
.Can someone take a look into this please? Thanks.
The text was updated successfully, but these errors were encountered: