jogramming / dshardmanager

Simple shard manager for discordgo
27 stars 5 forks source link

[Request] Example of updating status or using handler #6

Closed bkuhl closed 6 years ago

bkuhl commented 6 years ago

I'm writing my first Discord bot and would appreciate if you were able to update the documentation here to provide an example of how to utilize one of the handlers. Specifically in my case I'm trying to update the status of the Discord bot.

jogramming commented 6 years ago

you simply add a handler for the ready event, you can add handlers to the manager which will pass on all handlers to all shards.

(I'm typing this from memory so might not be 100% accurate)

manager.AddHandler(func(s *discordgo.Session, r *discordgo.Ready){
    s.UpdateStatus(...)
})

Reason you should do this in the ready event is that when the shard disconnects and is not able to resume, the status would otherwise be lost, but since a new ready event is fired then its updated again.

bkuhl commented 6 years ago

Thanks for the quick response.

    manager.AddHandler(func(s *discordgo.Session, r *discordgo.Ready){
        fmt.Println("Updating status to: " + status)
        s.UpdateStatus(0, status)
    })

I added this handler per your suggestion and am not seeing the code get executed, but the bot is connected to my Discord channel.

jogramming commented 6 years ago

are you adding that before or after starting it? it might not catch the ready event if you're adding it after you're starting it.

bkuhl commented 6 years ago

:facepalm: What a stupid thing for me to do. Yes, thank you - that resolved it.

bkuhl commented 6 years ago

Thanks for taking the time to build/open source this. I hit the 2,500 guild limit this morning so our production app went down (didn't see anything about 2,500 guild limit in the docs) and this made getting past that outage pretty simple.