Problems after having 2 shards

let server = client.guilds.cache.get('server_id')
let category = server.channels.cache.find(c => c.id === 'category_id' && c.type == Discord.ChannelType.GuildCategory);
let server = client.guilds.cache.get('server_id')
let category = server.channels.cache.find(c => c.id === 'category_id' && c.type == Discord.ChannelType.GuildCategory);
TypeError: Cannot read properties of undefined (reading 'channels') My bot now uses two shards, so it's also running the ready event twice. What's a fix for this?
11 Replies
Unknown User
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
monbrey
monbrey•3y ago
What is this code supposed to be doing? Guilds only exist on a single shard, that's the point
Iced Queen
Iced QueenOP•3y ago
It's supposed to get a channel from a server the bot is in
monbrey
monbrey•3y ago
Well that server is only going to be on one of the shards
Iced Queen
Iced QueenOP•3y ago
So what am I supposed to do instead?
monbrey
monbrey•3y ago
You haven't explained why it needs to do this
Iced Queen
Iced QueenOP•3y ago
To update the channel (category)'s name
monbrey
monbrey•3y ago
And your bot needs to do this every time it starts?
Iced Queen
Iced QueenOP•3y ago
It does it every 10 minutes approx
monbrey
monbrey•3y ago
Yikes Well anyway, I'd just check if server is defined That way it'll only be running on the shard it's meant to Stuff like this is going to continue to cause problems as you scale the bot up though
Iced Queen
Iced QueenOP•3y ago
Then I probably shouldn't do that? 😅
Want results from more Discord servers?
Add your server