Sharding Help
I want to increase my bot shard count to 2 but it is not working and there is no guide for that
Only for auto guide is given
91 Replies
@Inky I tried
It is only spawning 1
Like I did from auto to 2
How many guilds is the bot in?
155
Its getting unknown interaction issues and all
People said me to shard
It worked properly for 1 months with 1 shard
Then idk from past days the issue coming again
I tried this
But then idk how to call in const Client
On net it is coming to do process.env.shard_id
But idh any process.env and how to get shard_id?
client.shard.ids[0]I put this in const Client?
No
Itβs how you get the shard id
Only useful for debugging tbh
Yeah so in const client I keep shards auto and in shard manager I do to 2?
You donβt specify anything in the client
Ohk
Const client = new Client({intents})
Like this right?
Yea
But then it is like duplicating my prefix commands
Wdym?
Commands appearing twice?
Yes
Logs are expected to appear twice
You told it to run 2 clients
Like I have prefix commands as well
So they give response 2 times
(and side note, but you should not deploy your commands every time your bot starts, only when you make changes)
And for like load commands and deploy I do on first shard right?
Itβs also a bit concerning that you are running express in here
Express I will run on first shard
Like the main things like command deploy and loading and express I run on the first shard?
In the future, you should just move it into the ShardingManager
I have separate file for
express app
Index.js
and bot.js(sharding file)
Thatβs fine
Issue is that ur initializing it in the client
You meant like putting shards: auto in client?
No
Then?
Iβm talking abt other modules like express
And deploying commands
as i mentioned, command deploy should not be ran at all alongside the client. You should have a separate script that deploys. Your commands wont magically undeploy every time your bot starts
Stuff that shouldnβt be running on every shard
Oh (client) parameters?
Ohk
I will try to do that what you guys are saying
Then will update you what happened
Alright
You can use an if statement to make the first shard to it and fix it later
Iβm more interested in ur commands replying twice
I have messageCreate for prefix commands in index.js
Ig I was doing wrong sharding that's why it happened
I will try again with how you guys said
Oh, you still had shards: auto in the Client?
See this error coming :
β οΈ Error in auction system:
Like it works perfectly fine for first 10 mins
Then this comes
Does the modal show?
No
It says int fail
After 10 mins of bot uptime
If I go restart bot rn it will work perfectly fine
Either an internet issue or smth caused the bot to take too long to respond
Host issue?
Itβs possible
That's what I also think ig
Are you able to see cpu and ram usage of the bot?

I removed sharding and then it worked for now 25 mins
With sharding it worked for 10 mins
When it errors, does it like keep failing if you keep trying again until you restart?
Yes
Can you show modules/auction.js?
And mark line 97

Ok
Line 32 to line 99
Line 97 is await interaction.showModal
Why fetch existing auction?
I donβt see it being used
also, just to inform, if your bot is in 155 guilds and getting unknown interaction a lot, increasing shards wont really help, you'll have to look into your network or host
sharding isnt really beneficial until around 2000 guilds
Oh that was for before like I was limiting if user has exisiting auction they can't request again
I removed the if statement
It could be the db call not finishing fast enough
You only get 3 seconds to reply/respond/etc or defer an interaction upon receiving it
Oh
I have like 5k documents π
In that collection
It is because of that?
most likely yes, you are doing a lot of db calls thats slowing down the modal showing
also, interaction.member exists, you dont need to get it from cache
Ohh
But slash commands also give application not respond
const member = interaction.guild.members.cache.get(userId);
Instead of this I do const member = interaction.member(userId)
no, just interaction.member
:property: ButtonInteraction#member
discord.js@14.21.0
If this interaction was sent in a guild, the member which sent itdont just guess
Also in slash commands it gives application not respond
On slash command @Inky
It comes application not respond I have like deferreply as well
Then your code is not reaching that defer
Figure out where code execution stops
If you aren't getting any errors, try to place
console.log checkpoints throughout your code to find out where execution stops.
- Once you do, log relevant values and if-conditions
- More sophisticated debugging methods are breakpoints and runtime inspections: learn more@Inky can you help me sort out my bot if i give you access?
No. We are here to help you. Not fix stuff for you
Start by the beginning
Your unknown interaction issues wont be solved by sharding
Then what should I do now
Fully built bot from scratch again?
No
Look at whats causing the unknown interaction errors
You're taking longer than 3s to respond
im using defer reply
immedietly
and it is coming in all commands
Whether thats your code or your host, thats up to you
And what happens in discord
Does it show application did not respond, or application is thinking
application didnt respond
even though i have deferreply
Sounds like a host/ network issue then
Your code is not even reaching that defer in time
Thats your issue
And your stack points to a .reply
Not a deferReply
async function donoCheck(interaction) {
try {
await interaction.deferReply();
it have immedietly
defer
yet your stack is still showing .reply
how π
issue happening cuz of this?
There isnt a single deferReply in that code
thats the main one which executes command
if i like put deferreply in this and then in all commands i use editReply instead of reply
will that fix this?
thats step one yes
.
You need to figure out why
Either you are doing too much async stuff or its a host issue
Start by deferring the moment you receive the interaction
If it still happens, its a host issue
ok
consider making cleaner code and adding comments to explain things such as what the fallback handler does etc and yeah
thats not the current focus though
@treble/luna I found the main issues
I deferred all commands
the bot slows down after sometime of starting which leads to slowness how to prevent that now?
Due to slowness buttons give unknown interaction
to optimize buttons we use deferUpdate?
buttons aren't "optimized"
you should just find what's making your bot slow down
Too many messageCreates?
And interaction creates
Prefix commands are main cause
how do you know that?
and why do you think that
you'd also ideally only have 1 listener per event and pass your logic down using handlers
I'm suprised you even got approved for the content intent
but that still shouldn't slow down your code
Yeah that's what I thought to make async function for all and then load them
And use in a single interactionCreate/messageCreate
I learnt from them
smart to publicly announce that
what's the "trick" supposed to be, if they allowed it then it doesn't sound like a trick at all
Trick like using separate messagecreates and all
Btw it got fixed
By changing host
It washost issue
Thanks for the help