Closed bkuhl closed 5 years ago
I was able to disable discordgo's underlying tracking of everything which was consuming ~13GB of RAM on the 92k servers my bot was connected to. After disabling tracking usage went down to ~400MB. Here's how I disabled tracking:
func main() {
// other bot code
manager := dshardmanager.New("Bot " + token)
manager.SessionFunc = customizeSession
// other bot code
}
func customizeSession(token string) (*discordgo.Session, error) {
s, err := discordgo.New(token)
if err != nil {
return nil, errors.WithMessage(err, "customizeSession")
}
// Don't store any messages in the history
s.State.MaxMessageCount = 0
// Disables all state
s.StateEnabled = false
// We don't need to track the state of anything with the servers we connect to
s.State.TrackPresences = false
s.State.TrackRoles = false
s.State.TrackEmojis = false
s.State.TrackMembers = false
s.State.TrackVoice = false
s.State.TrackChannels = false
return s, nil
}
Would you be able to add an example on how to customize one or two of the session settings using
SessionFunc
in the./examples
directory? I've been tinkering with it for a bit and can't get it to work.