disgo icon indicating copy to clipboard operation
disgo copied to clipboard

Example Request: Sharding

Open bkuhl opened this issue 1 year ago • 4 comments
trafficstars

I'm on an ARM OSx device.

I'm not very familiar with golang and am trying to migrate my Discord bot to use your library. It's a sharded bot. I'm following the docs here and am encountering an error I don't understand. I was wondering if you'd be able to add a full example of how to run a sharded bot as I seem to be doing something wrong.

	bot := &disgo.Client{
		Authentication: disgo.BotToken(token),
		Config: &disgo.Config{
			Gateway: disgo.Gateway{
				GatewayPresenceUpdate: &disgo.GatewayPresenceUpdate{
					Status: status,
				},
			},
		},
	}

	bot.Config.Gateway.ShardManager = new(shard.InstanceShardManager)
	s := bot.Config.Gateway.ShardManager

	s.Connect(bot)

I keep getting

bot-1  | panic: runtime error: invalid memory address or nil pointer dereference
bot-1  | [signal SIGSEGV: segmentation violation code=0x1 addr=0x30 pc=0x3b5360]
bot-1  | 
bot-1  | goroutine 1 [running]:
bot-1  | github.com/switchupcb/disgo/shard.(*InstanceShardManager).Connect(0x400010e580, 0x400010e500)
bot-1  |        /go/pkg/mod/github.com/switchupcb/disgo/[email protected]/instance.go:86 +0x30
bot-1  | main.main()
bot-1  |        /app/main.go:64 +0x354
bot-1  | exit status 2

bkuhl avatar Mar 02 '24 16:03 bkuhl

unfortunately, i dont think this project is being maintained anymore... this looks really nice to use (and i find dgo really annoying to use so) i would help but im also brand new, a fucking moron, and idk where to start lol. 😭

imide avatar Mar 31 '24 04:03 imide

We switched to use https://github.com/bwmarrin/discordgo and github.com/servusdei2018/shards for sharding and it's working great.

bkuhl avatar Apr 01 '24 13:04 bkuhl

unfortunately, i dont think this project is being maintained anymore... — @imide

I was homeless.

if you'd be able to add a full example of how to run a sharded bot as I seem to be doing something wrong. — @bkuhl

The short term fix is to use `bot.Config.Gateway.ShardManager.SetNumShards(2)'.

The long term fix is that the Limit struct should not be nil.

I can implement this fix when I want or when I am paid to do so. However, you are using discordgo, so no payment is expected.

Here is what caused the issue.

Line 86 is a reference to totalShards = sm.Limit.RecommendedShards

The instantiated shard manager has a nil Limit struct.

When you call Connect, totalShards is not set, so it attempts to read from a nil pointer.

The shard test doesn't catch this issue because it calls bot.Config.Gateway.ShardManager.SetNumShards(2) which sets totalShards to 2.

The short term fix is to use that line of code and set the shards to a given number.

The long term fix is to make sure there is a limit set and consider whatever reason I had for not doing so.

https://github.com/servusdei2018/shards

Does this package make you use a lot of for loops to call code on each shard?

switchupcb avatar Jul 09 '24 15:07 switchupcb

I was homeless.

oh no! i hope you're back on your feet 👍🏼

imide avatar Jul 10 '24 16:07 imide