#archive-sharding
12465 messages · Page 3 of 13
[SHARDING_READY_TIMEOUT]: Shard 0's Client took too long to load
I got this error a long while back and I don't remember how I fixed it. Now I got it again and I'm not sure what to do
Here's my sharding file
const config = require('./config');
const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./shard.js', {
totalShards: 'auto',
token: config.token
});
// Trying to spawn the required shards.
manager.on("shardCreate", shard => {
shard.on("ready", () => {
console.log(`[DEBUG/SHARD] Shard ${shard.id} connected to Discord's Gateway.`)
shard.send({type: "shardId", data: {shardId: shard.id}});
});
});
manager.spawn().catch(error => console.error(`[ERROR/SHARD] Shard failed to spawn ${error}`));
So I'm in 40K servers and have been using external sharding - or sharding manager.
From what I've heard, the primary benefit of using external sharding is memory usage. What are the other benefits, if any?
The reason I ask is, 40K servers means 40 shards, which means:
• 40 MySQL connection pools — each of which reserves a huge chunk of memory.
• 40× cached resources — such as images used for rendering.
• Etc.
My VDS sits at 1-2% CPU. However, I've consistently had to upgrade because of memory, mostly thanks to MySQL. I've recently integrated slash commands, which has completely eliminated my need for GUILD_MESSAGES, so I no longer have to test each message against ~25 commands. This will likely reduce my usage even further. I don't cache users, messages, anything, and fetch it all when needed.
Can I get away with internal sharding?
How much is the maximum amount of total guild count internal sharding can handle?
Its likely ideal upto 32K i think
What would limit its ability to go higher?
Happened to see this https://www.npmjs.com/discord-hybrid-sharding
Utilising internal sharding and external together, it claims to reduce memory usage
I think you cant move around servers in case one process goes down. Or is that for clusters? Not sure
I want to send an embed between shards and I made it like this:
channel.send({ embed: JSON.parse('${JSON.stringify(messageToSend)}') });
But I got this error:
UnhandledPromiseRejectionWarning: SyntaxError: missing ) after argument list
and points todiscord.js/src/client/Client.js:425:17
What did I do wrong?
You are missing ) somewhere in that line
I know that it derivated it means that, but I double checked it and there's no missing )s in this part:
channel.send({ embed: JSON.parse('${JSON.stringify(messageToSend)}') });
and If I try simply:
channel.send(messageToSend);
It's output is [Object object]
[14/05 07:24:56][LOG] [WS => Shard 2] [HeartbeatTimer] Didn't receive a heartbeat ack last time, assuming zombie connection. Destroying and reconnecting.
Status : READY
Sequence : 396778
Connection State: OPEN
[14/05 07:24:56][LOG] [WS => Shard 2] [DESTROY]
Close Code : 4009
Reset : true
Emit DESTROYED: true
[14/05 07:24:56][LOG] [WS => Shard 2] Clearing the heartbeat interval.
Why doesnt the shard reconnect after destroying 
to use template literals you will need to use ` not '
you probably made a typo on that
since your cpu usage is very less, you can combine internal sharding with sharding manager, which will save a lot of ram. With the combination you would need 8 shards and 5 internal shards on each shard (would be the 1/5 ram usage of your current one), as Joshua suggested, you can do it with the package. It combines both or you have to make your own solution
1/5? that doesn't sound right
I use ` on the start and end of the template
But in the code you sent you used '
.
Hi, how does sharding work?
My bot uses another class that extends the discord.js client
That class has a function that loads everything and logs in the bot
Will sharding work when I call this function in the main file? (slowmode is a bit annoying)
Sharding spawns every time new processes, 50mb is node usage for one process. He spawns 40 shards means 2gb, on 8 shards it would just be 400mb
How can I make a rolling restart on my shards?
To clarify, restart one shard at a time to minimize downtime when making changes
well, if you specifically mean overhead of sharding alone, sure
but if you're talking about overall size, caches won't play as nicely
you could simply broadcastEval a process.exit
using shard id
so that would make that sharding client restart that shard? when it detects it went offline?
sharding manager restarts processes when they exit, yes
sounds good, ty!
const data = require('./data.json')
const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./index.js', { token: data.token, respawn: true, totalShards: 2 });
manager.on('shardCreate', shard => {
console.log(`Launched shard ${shard.id}`);
shard.on("ready", () => {
try {
shard.channels.cache.get("789294581333884948").send(`Shard ${shard.id} preparada.`)
} catch {
console.log("ERROR");
}
})
});
manager.spawn();
it never spawn the shards
?sharding
const { ShardingManager } = require('discord.js');
const Manager = new ShardingManager('./bot.js', { token: 'your-token' });
Manager.spawn();
https://discord.js.org/#/docs/main/stable/class/ShardingManager
For an in-depth guide: https://discordjs.guide/sharding/
that... is not what shard is
also, are you getting any errors? anything?
can't pull out answer out of thin air
nope, it doesn't throw any error
just doesn't work
what are you running
rn, this:
const data = require('./data.json');
const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./index.js', { token: data.token, respawn: true, totalShards: 3 });
manager.on('shardCreate', shard => {
console.log(`Launched shard ${shard.id}`);
shard.on("ready", () => {
try {
shard.channels.cache.get("789294581333884948").send(`Shard ${shard.id} preparada.`)
} catch {
console.log("ERROR");
}
})
});
manager.createShard(0);
manager.createShard(1);
manager.createShard(2)
i've tried with spawn and didn't work so now i'm trying with createShard
- this is not how that works. shard isn't client
- use
spawn()instead of calling createShard n times
what command are you using to start
a command to start..?
yes
that code doesn't run on its own
you have to start it
OHHH so that's the problem, i don't have any command to run it
wat
did you even attempt to start your bot
yes i did.
how
the bot runs perfectly, the problem is that the shards doesn't get created
how do you start it
with the button "start", i use replit
fairly sure that that button starts main file
which in 99.9% of cases is index.js
mmm
you have to go to the .replit file and change 'run=node shard.js'
ok now, it works, but, now express throws error, 'Port 3000 is already on use'
not djs
it's djs, i'm trying to init sharding and it doesn't create the shards correctly because the express throws error
Error: listen EADDRINUSE: address already in use :::3000
(node:1005) UnhandledPromiseRejectionWarning: Error [SHARDING_READY_DIED]: Shard 0's process exited before its Client became ready.
someone?
:c
Is there way to check if all shards has spawned?
@terse cairndon't run the server in index.js but in manager file.
Is it possible to "build" Client from array? (Using broadcastEval)
just after shardCreate, i try to use .eval but it says Shard 0 has no active process or worker
is there event for when worker is launched
code?
manager.on('shardCreate', async shard => {
console.log(`Launched shard #${shard.id}`);
if(commandList.length === 0) {
commandList = await shard.eval('Object.keys(Commands)');
console.log(commandList);
}
});
fairly sure that that event is emitted when the shard is created, not when it became ready. for that there is Client's ready event
yeah but i need to eval things
i don't care what's going on inside shard
then eval them in ready
uhmm how
?
how do i get client ready event if it's "inside" shard
the regular ready event on the client
in the file your manager spawns
i have to do it outside, not inside bot
why exactly?
because of how bot built
then make it not be built like that and use ready event on the client, which is de facto the thing that uses commands
manager has absolutely no correlation to messages whatsoever
i don't need messages or anything inside, just some thing
i'm hosting web api for it outside
from what i can see above, all you do is log commands
i can't make web server run 50 times inside every shard
not sure what is the difference between getting them form manager or from a shard
then don't
run server along the manager
and connect to the server from shard
shard -> manager's server
not manager's server -> shard

i don't quite get it
you know how websites work?
there is one server
and every browser connects to that server
as a client
it doesn't work in a way that your browser runs a local server and waits for the website to connect to your browser
same logic here. Run one server, in the sharding manager file
and then in ready event in shards, connect to that server and send whatever you need
i have to for example change some settings of bot in guild via api (oauth2)
and i'll have to do server -> shard not shard -> server
client makes request to server, server does things to shard where server is
and the question was just to get some variable from shard
immediately after it runs
again, get that variable in ready
there are tons of ways you can maintain a two way connection between manager and shards
websockets, pub-sub or whatever you want
but the general idea is to not run a server everywhere
so you tell me to make something like webhook or websocket server and then the shard will connect to it and send info via that
i think that's 50 times harder than just evalling from sharding file
no, not really
i just need to get 1 variable from the first shard that will connect
lol, i just don't think it's necessary
a harder way of doing things
not harder, but proper
it's really not hard to run a single websocket server
what's wrong with evalling things with sharding manager
why are you even evaling command list
because i need it for stuf
then read the directory
commands are inside the module files
then read the files
mfw running huge ass slow files that take 10 seconds to run just to get command list
you do it 50 times anyway
it was an example
and still, bad thing
why running for no reason
ok then
go ahead and use your eval
(it doesn't work which was the original issue)
and any other monkey patched solution
see
this is why i suggested multitude of things
but why it calls create event before it's created??
but you just said "what was wrong with my way that literally didn't work"
because that it's the event lol
it's shardCreate
not shardReady
for that tiere is client ready
literally
it would work perfectly if i got event smething like "shardLoaded"
it's called ready in client
gsjhgsdjkhd, yeah whatever
also, wrong
yes
because
and only later it awaits all promises from spawning
everything would be 5 times easier if event like that existed 
dude
why are you so opposed to using ready event
because have to make a server just for 1 (one) thing
no, you don't have to
wait is there way of communicating with sharding manager
you can even console log it
and read from stdout
and yes
gg
i have 549045903 of different stuff in console log
and === or startsWith() don't really care

i guess i'll prob have to remove almost all of console logs
i'm just about to hit 2500 servers and working on huge update with web dashboard and stuff
so how to send data to sharding manager inside shard?
k found
You could have listened to the shard ready event
That gets emitted after the client
at Timeout.onTimeout (/home/runner/Amity-Bot/node_modules/discord.js/src/sharding/Shard.js:163:16)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
(node:229) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:229) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.```
How would I handle this error?
?shardreadytimeout
Got this error: Error [SHARDING_READY_TIMEOUT]: Shard 0's Client took too long to become ready.?
The spawnTimeout can be set to -1 or Infinity to prevent future errors:
https://discord.js.org/#/docs/main/stable/class/ShardingManager?scrollTo=spawn. This can also happen if you call ShardingManager#spawn before attaching a listener to the shardCreate event which could create a race condition possibly preventing the shard 0 to perform a successful launch.
Could someone send me an initial bot for me? to train some things without a bugs
?guide
The official discord.js guide, maintained by core members of the community https://discordjs.guide/
Quick question: if my bot sends a message with a custom emoji, there's no need for me to use use broadcastEval to pull the id and name from cache if I alraedy know the id and name. I could just message.channel.send() with the <:name:id> as is. Am I right? I did this and it appears to work, but I just want to be sure. To clarify, I'm simply hard-coding the emoji name and id.
No you don't need broadcast eval i think
how do I get all the users in all the shards?
it should be like this right?
${results.reduce((acc, userCount) => acc + userCount, 0)}
because to show all the servers it is like that
ping me with the anwser pls
You could always try
how to get the shard ping?
users are just cached, when you fetch or process them, so you would not get all users, you have to rathe reduce the membercount of the guild
#client.ws.ping
this is the shard ping?
the shard ping, is the ping of the client, so you have to broadcastEval this.ws.ping
ok
what would cause this
As the string mentions, Discord wants you to reconnect every (15 min - 4h) to balance the load on their end.
oh
I was wondering about shards. My bot isn't completely huge, but what is the benefit of shards, and what are they used for?
Sharding splits ur bot into separate processes
You wanna use it before you hit 2500 because its required by discord at that point.
Discord requires you to do it at 2500 guilds
It distributes the load of events across how ever many shards you have
Is there a way to get the whole GuildMemberRoleManager#cache from broadcastEval? @dense cape
You can, but it would be a plain object
Would I not be able to call .get()
No
Collection would be converted to an array of arrays
hmmm
What are you trying to achieve?
Getting a set of roles from a guild via broadcastEval then I run a for loop through my set of roles in my DB and attempt to call .get() and then if the role is found display it on my dashboard for a role select dropdown menu
So you need to list the roles, then be able to get a role on command?
Yes
Are these actions separate endpoints?
No
You could just throw the array of arrays back into new Collection/Map, then get the role data
ohhhh
Hmmm I am wondering how the best way to do that is
Wouldn't it just be new Collection(data)? or should I run a loop to put it all in?
The former
Why do I not know what former means all of a sudden in this context
First 
Ah
Finally, I have been working on a fix for forever and you helped so much @dense cape
Well, I am now having a issue where the collectionn isn't actually inputting any data values
Show code
let roles = await client.shard.broadcastEval(`this.guilds.cache.find(g => g.id === '${req.params.serverID}').roles.cache.toJSON()`)
console.log(roles)
roles = new Collection(roles)
http://img.extreme-is.me/nA3onRrazclmDDuu (I logged both of my 2 collections at bottom)
broadcastEval still returns an array of data
Oh wait
One item for each shard return data
But it would only return one set so I need to do roles[0] when I pass it
Yea
Lets see
Both collections still empty?
console.log(roles[0])
roles = new Collection(roles[0])
console.log(roles)
@dense cape
Huh, it returned an array
You could do [...<Map>] in the eval
Where?
In the eval
Instead of calling toJSON, wrap the Collection in an array and use the spread operator
I don't follow 
How should I wrap it?
remove the .toJSON() and switch it with?
Guild.roles.cache is a Collection (extends Map)
Yes
If you do [...<Map>], it’ll return an array of entries [key, value] that can be easily converted back to a Map/Collection
Why is my brain breaking
[...<Guild>.roles.cache]
ahhhh
You would have to add a check to make sure the guild is found tho
Yeah I already do
I just gotta figure out how to do this because my brain is hurting for some reason, I am for some reason thinking I am supposed to do the [...roles.cache] inside the broadcastEval, I can't understand jack shit rn
Yes
Is that right?
Error [SHARDING_READY_DIED]: Shard 0's process exited before its Client became ready.
`same error ;/
I put manager.respawnAll() in a setInterval and that error is gone
oh thanks for the help
did the tags solution not fix it?
nope
hmm, try that i guess
there's no option coming like that
can you show your sharding file?
yes
const {ShardingManager} = require("discord.js");
require("dotenv").config()
const shards = new ShardingManager("./index.js", {
token: process.env.TOKEN,
totalShards: "auto"
});
shards.on("shardCreate", shard => {
console.log(`[${new Date().toString().split(" ", 5).join(" ")}] Some shard is ready lol #${shard.id}`);
});
shards.spawn(shards.totalShards, 10000);```
wait a min
Seems clean for me 
tf ,thank you i guess?
sure waiting
shards.spawn(1, 1000, -1);
can you try this?
sure
ping me with the response 👍
no response
its just stuck
nothing's happening its just stuck
hmmm
¯_(ツ)_/¯
...
now i am out of ideas why, you would have to wait until some one who knows about this comes
sure
does it spawn shards at all?
if so, did you try listening to debug event on the client?
eventually, do you do some tasks in client file that could probably disallow it from readying up?
His question has been answered in a different channel, he has to wait out a 15 hour too-many-logins cool down
i love channel hoppers.
why does my bot respond two times
nvm i fixed it
Is there a way to have per shard status? So each shard has their shard number in their status
?docs ClientUser.setActivity
Use options.shardID
How to define shard in other files
?help
?docs Intents
hello , who can help me with sharding? ty
guide can
whats the benefit of sharding?
splitting load that is eventually enforced on you
so bot goes faster?
no
not raelly
it more prevents it from slowing down, since one shard only handles some of the guilds
who?
I saw it, but still need help
well, if you actually ask, someone might help
note how you pretty much wasted 9 hours because all you asked was "who can help me", where in reality such question is pointless
In those 9 hours I slept xD
i was acting stoopid for like idk a long time
i know that you slept
but if you would ask actual question, you would have a chance to get up to answer
and not to need to ask, and then wait for any answer again
which you btw still not do
so you're stalling getting any answers
Okay, need to do a shard for each command ? or just the main file of the bot
Do not really understand in shard
sharding spawns copies of your main file
your main file handles commands and events and all that
so i need to this and that's it? ( i have commands handler)
const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./bot.js', { token: 'your-token-goes-here' });
manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`));
manager.spawn();
yes
ok , Thank you very much
it is not recommanded to spawn manually new shards, use the method #manager.spawn(shard_count, spawn_delay, timeout)
yes, so whats your question?
How does one get information on their bots shards? (Viewing how many guilds in said shard, viewing if shards are down etc etc)
See the pic, it's in bot.js and I have the following code in text in the server.js file, how can I make it work? Btw, the server.js is the file which starts the bot in package.json.
const manager = new ShardingManager("./bot.js", {
token: "",
totalShards: 2
});
manager.spawn();
const uptime = bot.channels.cache.find(channel => channel.id === "835884721463623721");
manager.on("shardCreate", shard => console.log("Shard Number #${shard id} is now online!"));
manager.on("shardCreate", shard =>
uptime.send("The Shard ${shard id} is **now** online and running the smoothly!"))```
Error: bot is not defined
Yes, it isn't defined in the sharding file
So how can I make it work?
What should I add in the sharding file?
Or what can/should change?
How does one get information on their bots shards? (Viewing how many guilds in said shard, viewing if shards are down etc etc)
Shard 0's process exited before it's Client became ready.
Why does this happen?
My bot has been fine since now.
Ah I found the issue.
Just a bit of code I added was stopping my client from logging in.
I know, my main file has code in aoi.js, see the msg above pic.
I nees to start the shard file and not the main file ?
Yes
Ok
All shards ? @terse cairn
In this link @terse cairn
client.shard.count
Ah
If I keep multiple shards(0,1,2) while having 512mbram and 1GBssd, make the bot ping high?
For some reason, I just added the shards and the ping is 700+
What is it? I can try to.
What i need to put here ?
In the "()"
manager.spawn();
https://discordjs.guide/sharding/#broadcasteval follow this
For me to
Hmmmmmmmmmmm
Maybe the global database might be lagging? There might be a lag spike?
Or maybe did our host database had a lag spike? Not sure if our host is same.

Anyone know why I get a high ping in shard?
On host or selfhost ?
Host
But , i try 2 other hosting , and same ping ( high ping )
Maybe you didn't choose the right server !
Believe me I chose the right server lol
I believe its in shardingmanager's docs somewhere
@terse cairn Have you got any idea of how to get the bot to start sharding? Having trouble with it myself
when I try to start my script, looking very similar to this, it crashes my VPS and throws a lot of errors
What i need to put here ?
In the "()"
manager.spawn();

manager.spawn([ShardCount], [timedelay], [timeout])
Yeah, those are all 3 params
?docs ShardingManager
And anyone know why I get a high ping with shard?
Sharding should not be used unless you either
A. Have a music bot
B. 1k+ guilds
it can actually hinder performance normally sometimes
My bot is on 740+ servers, and there are bots on about 100 servers that do shard and nothing happens
Are you using commands with sharding in mind?
sharding does use excessive amounts of memory
I'd recommend a VPS provider with an unmetered plan.
how many guilds is the recommended amount for music bots? I thought it was 1k guilds for everything?
DIscord recommands 1k, but you can go higher, up to 2000 (2500 is the max)
i know that, but how is a music bot any different?
It's up to how much memory each shard is gonna need based on what you're doing. Audio stuff has higher demands than text
How much data do you process? could you check the ram usage of external buffers, log out process.memoryUsage()
oh ok, so is it recommended for music bots to shard earlier?
Is
manager.spawn([0,1,2], [25000], [300000]) the correct Usage? And it's supposed to start the shards 0,1 and 2 with a interval of 25s?
not sure why would you want to spawn them 25s apart, but still
if you want to spawn only those 3 shards, pass them as options to ShardingManager
spawn() doesn't take such thing at all
Okay.
And what's wrong here?
anyone know why I get a high ping with shard?
your client did not got ready, you can use a option in the manager.spawn, where you wait until the client gets readt
Hi guys, what would the limiting factors for the size of internal sharding be? Is there an established estimated limit to it?
Ur cpu would be the main limiting factor
Bc internal sharding runs multiple ws on one cpu/process
Can I run code in ShardingManager simlar to with broadcastEval?
Sorry to bump but it's been a while. Anyone able to help?
what do you even mean
from a shard, run code with access to the shardingmanager and its functions/properties
in the parent process
what are you trying to do
run code to restart shards individually, including the one I initiated it from. I can’t run it on that shard since i’m stopping the process so I want to run it on the parent process (sharding manager)
yes but I want to do it one at a time so I can’t use restartall
I shard my music bot at 72 guilds, that should give you a good idea of just how much memory is used
I have a question. So how would I pass data from my database into the separate shards
Ur shards should be fetching from the db
@prisma jewel
the ready event is only fired when all shards are ready, right?
All shards handled by the emitting client, clients in other processes / workers do not count here.
Do I see correctly that you are using a second bot account to check shard status?
good idea, thank you
back to your question: it may be a server provider issue
thats normal that internal shards reconnect and resume, it can be bc of the internet connection or sometimes DIscord closes the connection.....
welcome
How exactly would that be done
A cluster means a ShardingManager correct?
What responds with the guild count in all the shards?
And how can get all the guilds from all shards?
And what about all members from all shards?
How can i map all of the shards?
ShardingManager.shards.forEach I think
broadcast client.guilds.cache
same with members
@next plaza Does .fetchClientValues() work with something like this
when you load it on the client, yes
thats in the client's module.exports, so I assume so
and it extends discord.client
So @next plaza this should work?
I'd use client.shard.fetchClientValues('guilds.cache.get'), with the only issue being that it returns an array, and a promise, so you have to use await or .then()
try and see xD
and all properties will not be there
Ah if you're trying to pull properties than your idea is better
on broadcastEval it is the same xD
damn discord.js is not making sharding easy lol
I feel like I may be about to hit a 429 because I forgot where my heartbeat setter is and I can't set it's heartbeat to 4 minutes instead of 20 seconds
it definitely did not
you can't change internal stuff
you can inject some code and overwrite properties, but this will break the libary
so how can I pull data from the database across shards
why dont you fetch it from the current shard?
does it have database instances?
you can create one???
i have a database already
yes, you can run the database an all shards
on the bot instance itself
Alright, thanks
Never got a full answer on this, can someone help?
shard.respawn(shardID)
?docs shard
I already know how to do that. As I said before, I need to access the parent process from the shard and run the code from there because the shard process that initiated it is stopping.
I don't think that is possible. There is no real parent process, the shards are independent I thought
Isn't the sharding manager the parent process? If there isn't a parent process then how would the shards get respawned if the close?
oh yes, the sharding manager is the parent. You'd have to call that in your shard.js file somewhere
I forgot that shardingmanager existed lol
Yes, I'm trying to send a message from a shard to that process to run the code for the restart.
?docs shardingmanager

wait there isn't a shard death capture
When my shards die they respawn on their own, i don't think I understand what you're asking
I already have the code to actually do the restart. The thing I still need is a way to send a signal from a shard to the manager to run that code.
I think if you wanted to restart a specific shard, you could just simply kill the shard
shard.kill
and it will respawn
That's not what I need. Again, I already have the code for the restart. Due to what it does I can't run it on the shard so I'm running it from the parent process. Hence why I need to send a signal to it.
manager to shard or shard to manager
shard to manager
use client.shard.send()
this will send a message to your sharding manager and you can listen on it with manager.on('message')
Ahhh, I knew I was forgetting something, .send is your best bet
What would the message be? Can I just use whatever? And how would I receive the message?
@next plaza I meant to ask you, if I wanted to index the database on the shard would I just do client.shard.db?
?docs shard#send
There should be documentation from there
Yes I have the docs open now. The type says any which is why I wanted to make sure there aren't any requirements for the format.
lol what? , no, you do not have to load the database on the client, you can run the database on every shard, btw are you using sql?
when you use child processes, you can send nearly everything
better-sqlite3, and I think you misunderstood me. I'm asking if I want to pull data from the database that is locally on the shard, would I do client.shard.db
client.db returns null
on worker_threads you cant bc of the structured cloning algorithm, you have to stringfy them first
Ok. And to receive it I would just listen for a message event?
Got it, thanks for your help!
why do you have to pull the data to a another shard?
no no, I have to pull data on the current shard
it comes up, where you load it, on which variable
its in my client.js under client.db = require('./utils/db.js'), however client.db returns null
how did you loaded it?
and what did you executed?
this
bruh, you didnt exported this file
last 4 lines export settings and users
which are the 2 data tables
and when you broadcast (this.db), it returns null?
client.db, as its in a client.on('guildMemberAdd', async(client, member) => {})
how did you bind your events?
filesync
and why is it client.on ?
what should it be
I'm still migrating to shard code and I'm generally unfamiliar with it all.
loadEvents(path) {
readdir(path, (err, files) => {
if (err) this.logger.error(err);
files = files.filter(f => f.split('.').pop() === 'js');
if (files.length === 0) return this.logger.warn('No events found');
this.logger.info(`${files.length} event(s) found...`);
files.forEach(f => {
const eventName = f.substring(0, f.indexOf('.'));
const event = require(resolve(__basedir, join(path, f)));
super.on(eventName, event.bind(null, this));
delete require.cache[require.resolve(resolve(__basedir, join(path, f)))]; // Clear cache
this.logger.info(`Loading event: ${eventName}`);
});
});
return this;
}
and you have the event on another folder ?
guildMemberAdd.js
it should be
module.exports = async(client, member) => {
}
its exporting it all
it all worked before I started sharding, the second shards started, it broke my code partially, all of the breaks happening in the database
how?
the same way you said
hey @crisp coyote, why did you remove <ShardClientUtil>.ids in kurasuta?
var gs = []; client.guilds.cache.forEach(g => {gs.push([g.id, g.memberCount]);}); gs.sort(function(a, b) {return b[1] - a[1];}); var msg = ""; for (var i = 0; i < 11; i++){msg = msg + String(i + 1) + ": " + client.guilds.cache.get(String(gs[i][0])).name + " at " + String(gs[i][1]) + "\n";} message.channel.send(msg);```
i have made this lil code to check the top 10 largest servers my bot is in, but it doesn't work as my bot is being sharded. could someone help?
I would make use of broadcast eval to get the top 10 guilds from each shard, then pick the guilds with the highest member count of all the shards until you get the true top 10. From there, just map and join the array to however you want it to be
how do i do it, exactly? broadcast eval for the client.guilds.cache.forEach and will it do so?
You’ll want to return the top 10 guilds from each shard
I didn't remove anything 
<ShardClientUtil>.ids is undefined
it should be an array
an array of shard IDs?
for that use ShardClientUtil#shards with Kurasuta
i specifically didn't call it IDs cause it would mix Cluster and Shard terms up
which is bad in my opinion
oh okie thanks
I'm using client.guilds.cache.forEach to fetch memberCount of each guild and show total users.
Question is, what will i need to do if i'm sharding the bot?
@crisp coyote Is there a support server for kurasta?
Because my friend encountered an issue using the clustering package
👀 , ..., ask you question here , then they can help
Ahh okies
Anyone?
https://discordjs.guide/sharding/#broadcasteval this section of the guide shows exactly that
Hi
I’ve a question
What’s shards ?
Instances
Okay thanks!
Shards are child processes to shardingManager. Its basically breaking your bot into X amount of smaller bots and logging them into the same client. It keeps the bot working efficiently
So is .send a valid method to use to send data to the shard
or only data from the shard.
Can ShardingManager actually run typescript file?
it return SyntaxError: Cannot use import statement outside a module when running the typescript file
technically it should, but you have to use npx and pass it in the shard args
how do i fix?
CODE
'use strict';
const { token } = require('./config.json');
const { Intents, Discord } = require('discord.js');
const sharder = new Discord.ShardingManager(`${process.cwd()}/shard.js`, { token, respawn: false });
sharder.on('launch', shard => console.log(`launched ${shard.id}`));
sharder.spawn();
ERROR
const sharder = new Discord.ShardingManager(`${process.cwd()}/shard.js`, { token, respawn: false });
^
TypeError: Cannot read property 'ShardingManager' of undefined
at Object.<anonymous> (c:\Users\prtiu\Desktop\shard-test\sharder.js:6:29)
at Module._compile (internal/modules/cjs/loader.js:1068:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:933:32)
at Function.Module._load (internal/modules/cjs/loader.js:774:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
[Done] exited with code=1 in 0.786 seconds
.intents
?
.intents, not .Intents
ohh
CODE
'use strict';
const { token } = require('./config.json');
const { Intents, Discord } = require('discord.js');
const sharder = new Discord.ShardingManager(`${process.cwd()}/shard.js`, { token, respawn: false });
sharder.on('launch', shard => console.log(`launched ${shard.id}`));
sharder.spawn();
ERROR
const sharder = new Discord.ShardingManager(`${process.cwd()}/shard.js`, { token, respawn: false });
^
TypeError: Cannot read property 'ShardingManager' of undefined
at Object.<anonymous> (c:\Users\prtiu\Desktop\shard-test\sharder.js:6:29)
at Module._compile (internal/modules/cjs/loader.js:1068:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:933:32)
at Function.Module._load (internal/modules/cjs/loader.js:774:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
[Done] exited with code=1 in 0.786 seconds
idk
Then is it possible to run with yarn v2?
const Discord = require('discord.js')
or
const { Intents, ShardingManager } = require('discord.js');
new ShardingManager....
try and see lol
how can i do this ?
so now i have 0 shards so how can we increase it?
no, and its not related to sharding nor djs
Is the shader hard to use?
no
in the ShardingManager options or in the manager.spawn funtion
Why is the timeout 30s for shard respawning? why doesn't it take the initial spawn timeout value?
Manual shard count
How can I get the shard id of a client?
Nevermind, just found out the first element in <Client>.shard.ids is the client’s shard id
As an example, if you wanted to split the connection between three shards, you'd use the following values for shard for each connection: [0, 3], [1, 3], and [2, 3]. Note that only the first shard ([0, 3]) would receive DMs.
from the discord dev docs; I'm curious, is it possible to split certain intents for each shard, or is this just something that happens that can't be controlled? (So shard 0 receives x intents, and shard 1 receives y intents and so on)
@wispy ocean on Discord's end they're all separate, unrelated connections so yeah you can do that
you can't do it with djs internal sharding though, and i assume you can't with shardingmanager either
alright ty
How do we get the number of shards from broadcastEval?
You can just get it from <client>.shard: https://discord.js.org/#/docs/main/stable/class/ShardClientUtil?scrollTo=count
and what does that have to do with sharding ?
just awesome help...
what if we increase shards?
The amount of guilds per shard decreases
what if there are lot's of shards in 1 guild?
It won’t let you launch more shards then you have guilds
anybody know how to fetch guild number ext. from the sharding manager in the shard file? (I want to make an express server that shows stats about the bot from the main shard file but do not know how to fetch the number for all of the shards)
client.shard.fetchClientValues('guilds.cache.size') only works for individual shard clients
You want to use this then: https://discord.js.org/#/docs/main/stable/class/ShardingManager?scrollTo=fetchClientValues
ah okay, tysm
{"status":"200","shards":"2","guilds":"1,3"}```
require('dotenv').config()
const {ShardingManager} = require('discord.js');
const manager = new ShardingManager('./bot.js', {token: process.env.TOKEN})
const shardcount = 2
const express = require('express');
const app = express()
const AutoPoster = require('topgg-autoposter')
const ap = AutoPoster(process.env.TOPGG_TOKEN, manager)
ap.on('posted', () => {
console.log('Posted the epical stats to Top.gg!')
})
manager.on("shardCreate", shard => {
console.log(`I've launched the epical shard ${shard.id}.`)
})
manager.spawn(shardcount, 10000);
app.get('/', async (req, res) => {
const guilds = await manager.fetchClientValues('guilds.cache.size')
res.header("Access-Control-Allow-Origin", "*");
res.json({
status: '200',
shards: `${shardcount}`,
guilds: `${guilds}`,
})})
app.listen('6969');```
anybody know how can I get the total number of servers instead of per shard?
Cant, instead reduce and add the values from the fetchClientValues Promise array
okay
manager.fetchClientValues('guilds.cache.size') .then(results => console.log(`${results.reduce((prev, val) => prev + val, 0)} total guilds`)) .catch(console.error);
Ty
Np
enable the intent toggles in the developer portal
can anybody help me?
Add it up using Array.reduce or a loop
(error)
already did, i'm asking about smthn else 😅 ^
Code?
client.on('guildCreate', async (client) => {
const guilds = await client.shard.fetchClientValues('guilds.cache.size')
const guild = client.guilds.cache.get('822467921653137438')
const channel = guild.channels.cache.get('845704285656186900')
channel.setName(`🌍Guilds: ${guilds.reduce((prev, val) => prev + val, 0)}`)
})```
guildCreate gives you a guild, not a client
oh right, but than how would I do it?
Prob shouldn’t be updating a channel with live data like that tho, the rate limits are pretty hefty
I know but the bot isn't added to servers often so it shouldn't be an issue
And when it does?
I guess you're right...
How about making it update in an interval? @dense cape in a ready event (such as every hour ext...)?
I guess that’s fine
but how would I do it? I plan to take it from my API and update it via a different bot but would that update the channel?
@dense cape
The interval should be made in the manager file
managers can updated channels?
No, but you can tell the shard to update the channel
right
There is a way that if the Shard collapses it will reignite
it does that by default
@wet topaz so why sometimes the Shard collapses on me and never comes up again
which version are using of discord.js?
how can i access a node module inside of broadcastEval?
Good afternoon, I use the shardList function to spawn shards on different devices, but I can't get the total number of servers in all shards, only those of that device, is there a way to get it?
UnhandledPromiseRejectionWarning: #<Response>
pain
Thats not possible since non of the managers talk to each other, you could impliment:
- Your own ipc for the managers or shards to talk to each other
- Websocket connections same as above
- Have the stats stored in a database
why am i getting this error
⬤ debug [WS => Shard 1] Shard was destroyed but no WebSocket connection was present! Reconnecting...
⬤ debug [WS => Shard 0] Tried to send packet '{"op":3,"d":{"activities":[{"type":3,"name":"t!help | Shard 0"}],"afk":false,"since":null,"status":"online"}}' but no WebSocket is available!
⬤ debug [WS => Shard 0] [DESTROY]
Close Code : 4000
Reset : false
pls help
how can i kill all the shards that created from the sharding manager?
nvm
You can loop through all the shards and kill them on by one
?docs ShardingManager#shards
12.5.3
You can’t, that’s not how sharding works
Shards will receive events from certain guilds depending on its id and the number of shards ur using
Prob manually fetch the recommended shards count and divide by 2
One will round down and the other will round up and spawn that many shards
so a larger issue still, I can't seem to pull from my database on shards, I use better-sqlite3
Hi. I'm sharding my bot with typescript, and get this error
Also I extend Discord.ShardingManager class, if it matters
XD
Are u using child processes?
could you show your shard.js file?
import Client from "@/structures/Client";
const bot = new Client(process.env.TOKEN, {
partials: ['MESSAGE', 'CHANNEL', 'REACTION', 'USER', 'GUILD_MEMBER'],
messageCacheLifetime: 10800,
messageSweepInterval: 300
})
bot.start()
but shard works normally
your sharding manager file
import Manager from "@/structures/Manager";
const manager = new Manager('dist/src/shard.js', {
totalShards: Number(process.env.TOTAL_SHARDS),
token: process.env.TOKEN,
mode: 'process'
})
manager.start()
import Discord from "discord.js";
import ManagerLoader from "@/util/ManagerLoader";
export default class Manager extends Discord.ShardingManager {
public file: string
public supportGuildID: string = '712012571666022411'
constructor(file: string, options?: any) {
super(file, options);
this.file = file;
global.manager = this;
}
load() {
ManagerLoader.loadEvents()
}
async start(): Promise<any> {
this.load()
await this.spawn(this.totalShards)
}
}
this is manager class ^^
When doing using djs' way to set shards to auto. Do I set auto as string?
Yes
What do I need to change in my codes (command etc.) if I add shard to my bot
there's a guide on it, check the d.js guide
Pls send it
https://discordjs.guide, it's a topic in the sidebar
Ty
is there any way to disable the autorestart on error with djs sharding manager? A simple API error (SEND_MESSAGES) can crash my bot what is well... bad
is there a way i could check if any of my shards are down without the event?
?docs ShardingManager
there is no built in way do that, you will have to use client/sharding manager options + your own way for communication between these machines/ d.js client/shards
can you show the code causing this error?
ok wait i fixed the error, but the bot is just now spamming the same sharding error, btw this is the first time for me to try sharding ||although the bot is only on 1 server||
@coral urchin can u help me?
i actually dont know much about sharding asdlkjgngv
lol
i know absolutely nothing about sharding
can anyone help me?
(node:119388) UnhandledPromiseRejectionWarning: Error [SHARDING_READY_DIED]: Shard 1's process exited before its Client became ready.
Any idea?
your sharding code?
const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./bot.js', { token: [token], totalShards: 2, });
manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`));
manager.spawn();```
that's the main file code
try addind mode to the options
mode?
maybe to -1
in glitch.com code ${user} this is command of mentioning user then what is the command to mention user's avatar/profile can anyone help with it?
what
I tried process but still throws the same error, worker throws another canvas error for some reason
what am I doing wrong?
🤔
Thats the wrong method
You are trying to get the value of a property on the shard client not execute a function
Use that
oh! I understood. XD
Thanks!
Np
Oh. I have a problem
I'm trying to get User and send him message. This method returns object without functions.
I... of course, I can use API request or something like but...
Send inside of the eval
Why are you getting the user via broadcastEval? Is this being called from the sharding manager?
i'm tryin' to get user from another shard
Users aren’t affected by shards
Only guilds and guild* stuff (guild member, guild emojis, etc)
You can just do await client.users.fetch("id") to get the User
I have two shards
Both shards can have the user as well
idk. first shard can't
Could also be none
I think that only if the user is on at least one of the shard's servers.
otherwise returns null
ok, maybe im wrong...
It’s just easier to fetch from client using the method I described earlier
Don’t have to worry abt double dming or not even dming
oh. its working. thanks
I understood. client.users.cache.get - to get user in client's cache
client.users.fetch - just to get user.
😅 i'm dumb
Can someone link me an extremely detailed resource to what sharding is. I tried googling but didn't understand much
Why are my internal shards dying silently? This is the 4rth downtime in 3 days. One shard just dies silently and the rest follows. According to one of the issues in djs github - i install zlib-sync. Still no luck. Tried listening to SIGABRT - nope.
Currently at 5 shards (internal)
downgrade to stable, one of the reasons I did not upgraded to master branch, bc there are some problems with the websocket manager
btw do you get any errors?
Nope none. But i'm using stage channels for the music system & sticker detection, so ig downgrading is not an option
How can I put the current shard id to the bot's status?
you just have to add stage channels as structure, you can extend the channel struture and you have extend the message structures for sticker
Perhaps there are files i should replace in the master branch code with the files from the stable branch just for the stability of the branch?
The whole voice system changes, not just the structure. They introduced a base voice channel structure which ig affects several internal files?
for stickers u have to extend message afaik
Then how can I find the id of the shard the current process is on?
yes, you have to change a lot, Discord.js has a very nested structure. But thats the only solution...
listen to the shardReady event client.on('shardReady', shardID)
Rip
It took me 10 files to add Slash Commands and Interactions like Buttons on v12, and I didnt even fully add every feature, like the CommandApplicationManager
But when you do it, I can help you lol
perhaps moving to traditional sharding will help?
just asking which mode do u use?
the problem will be there too, but the percentage, that a Shard silently dies, would decrease. Since there is just 1 Websocket manager for each process (shard)
wdym mode
i mean process or worker ?
use process, In woker you will have some problems, bc they have an special cloning algorithmus (which doesnt support objects)
those are internal shards, websocket shards
hm
i prefer worker tho : (
Welp, i'll use winmerge to compare the files in the stable and master branch and see if i can bring up a solution since you've said that the stable branch avoids this issue
I had 10 internal shards running for over 10 days and they didnt had any problems
stable branch, right?
I'm getting Error [SHARDING_NO_CHILD_EXISTS]: Shard 0 has no active process or worker. when I do ```js
manager.on('shardCreate', (shard) => {
console.log(Launched shard ${shard.id})
shard.eval(`
this.user?.setActivity({
type: 'WATCHING',
name: \`Shard #${shard.id + 1}\`,
})
`)
});
you have to first wait until the shard starts
yes
How can I do that inside the shardCreate event?
you can do it on the client event, is much more easier
But how am I supposed access the shard id that way?
is the only shardCreate event only?
imean how many events are there for the sharding manager
listen on client.on('shardReady', (shardid) => { client.user.setActivity( ` Shard ${shardid}`, { shardID: shardid }); })
I didn't know that existed, thanks!
Well upon comparison, I dont see any major changes that would be the cause of the issue
you have to compare everything, which is related to the websocket, it mostly crashes bc of an TypeError on connection.url
o
You can add stage channels to discord.js v12 with discord-stage npm package
um in which file is it?
How would i get information of each shard i.e each shard's ping etc
what even is a shard, never heard of them until i read the docs but there was no explanation lmao
When you have a lot of guilds (sharding is mandatory at 2500) you can split up your bot, so each shard/instance of your bot handles around 1000-1500 guilds.
oh, don't need that my bot is trash lmao
Hi, How to use the shardIDForGuildID method
You give it the guild id and shard count and you get the shard id that will receive events from that guild
Oh, thanks
Why does it return an error?
this.client.shard.shardIDForGuildID(${message.guild.id}, ${this.client.shard.count})
The count should be a number
TypeError: this.client.shard.shardIDForGuildID is not a function 
It’s a static method
ShardClientUtil.shardIDForGuildID(…)
Thanks 
I will look today at it, I will ping when I find something xD
ty 😄
how can I get the ID of a shard from within the shard
<shard>.id
try ids
How would i get information of each shard i.e each shard's ping, etc?
something like this should help
Hmm, Helps me a wee bit but getting undefined:
ehhh
i think remove ping[9]
use await ofc
try a async function
yep
mhm now i gtg
Odd.
ofc it’ll be odd u have to call that function
?sharding
const { ShardingManager } = require('discord.js');
const Manager = new ShardingManager('./bot.js', { token: 'your-token' });
Manager.spawn();
https://discord.js.org/#/docs/main/stable/class/ShardingManager
For an in-depth guide: https://discordjs.guide/sharding/
Yeah, forgot about that. Been a hard day today haha. But yeah, nothing.
const pinged = await client.shard.fetchClientValues('ws.ping')
return pinged
that should work inside the function, if not try it in actual code,
also i have tutions rn : ( sorry
Just returning undefined. I'll have a go in the code itself but my hopes aren't too high.
also inside the eval command put this
let output = eval(text);
if (output instanceof Promise) {
output = await output;
}
this will make sure ull not get promise's
Right. Okay.
So that's what i added (whether to add the ping() just responded with the promises), without it just returns undefined :/
aaand u have to call it
ping()
Thought i did. Though like I previously said, returns the Promise part of which I'll fix when im next on pc.
yes then ull to fix the promise part
then itll show results 😄
Oh, great.
I'll sort that out, now.
@marble maple You're a star, thank you!
np : )
is there anyway to speed up bot launching with multiple shards?
Earlier I've seen a VSCode plugin here which helps the correct syntax highlight for the escaped broadcastEval snippet, but I can't find it now
Does somebody knows which plugin is that?
the #1 shard for my bot keeps switching status from idle to ready about every few weeks randomly.
does anyone have an explanation to why this happens?
the bot runs up to 7 shards at a time, so it's weird how it only happens with the second to first shard
Hello , i sharding my bot and i dont know how to send a embed in a custom channel :(
If the channel is not on the shard, you can use broadcastEval;
...broadcastEval(`this.channels.cache.get(id)?.send({ embed: ${embed.toJSON()} })`)
The ?. will make sure it only executes .send if the channel was found, which should only be the case on 1 shard
i use this and give this error
Well you shouldn't call it on null
You can only use client.shard if the process was spawned from a ShardingManager
nice
How did you shard your bot?
i make a file
and add this code
const manager = new ShardingManager("./bot.js",{
token : 'token',
totalShards : 2
})
manager.spawn()
manager.on('shardCreate', shard => {
console.log(`Shard #${shard.id} in onine!`)
})```
If you plan on running the bot on one server do I need to shard my bot?
sharding is for bots in 2500+ guilds
nope, when your bot is over 100k Servers, then you will get Big Bot Sharding, which allows you to spawn 16 Shards in a row instead of 1
(node:86) UnhandledPromiseRejectionWarning: Error [SHARDING_READY_TIMEOUT]: Shard 0's Client took too long to become ready.
any idea?
@spice frost client.on('warn', console.log)
client.on('debug', console.log)
then show me the output
can anyone help me with enmap database? it works well but not the bot is running in shards
but log what
just put console.log, that’s it, it’ll log what it needs to
Hey all, what's the benefit of sharding
None. Sharding is a requirement for bots over 2500 guilds. It doesn't inherently have any benefit.
Oh I see
pm2 allows for sharding but it would run my bot in parallel, which makes it respond multiple times to a single command
How would I circumvent this if I wanted to support sharding
use discord js’s sharding
pm2’s shard will be just local, ull have to use discord js or any other package for discord sharding
I used the sharding from the guide, but im still getting multiple responses for one command, how can i fix this
did you follow the guide to-point? your code matching the guide with nothing extra?
Yes
Nothing extra and nothing less, it launches two shard #0 tho i dont know why
are you using a process manager? like pm2?
How would i know?
Cause I've never used any package like that
do you use node in command-line, like node index.js
Sometimes i get stuck in an endless loop and then the bot keeps responding endlessly still i stop it
Yeah i use the command line
of course.
check these:
- accidentally running the process twice?
- accidentally accessing your bot's entrypoint from shard manager entrypoint?
How do i check the second
does the file that contains ShardManager access (require) the file that logs into discord?
Yes
that's bad
show me the line where you're requiring it and where you're using it
But thats what the guide had, unless i need to remove the client.login from my main file
Ok ill send it in a bit
you shouldn't be requiring the bot entrypoint if the bot file has an uncaptured Client creation
by "uncaptured", i mean that Client gets created without needing a call
ok
const { ShardingManager } = require('discord.js');
const { DISCORD_TOKEN } = require(`./config/config.json`);
const manager = new ShardingManager('./bot.js', { token: DISCORD_TOKEN });
manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`));
manager.spawn();
@tough idol this is my sharding code
just remove the params for the manager?
erm, you're not requiring it.
that's correct
ok thanks alot man
that should work fine
this?
yes
it launches two shards with id 0
or do i have to wait a while after closing the command line before starting it up again
that shouldn't affect it
this happens
would you like to take this to DMs? i feel like troubleshooting this will clog up the channel
if you dont mind
@terse cairn
on the client file (the file where your ShardingManager ISN'T located) are you logging in?
this is where i make my client:
if u didn't already do it, make sure u put client.login(token);
otherwise that shard won't login (I think, it doesn't work for me unless I do this, at least)
u have to do super.login(token)
inside the start function
Will djs support clustering in the future?
why is sharding rising my bot ping soo much?
like my bot ping now is 2000+
that shouldn't be the fault of djs.
an unoptimised database handler could be the problem
on the start its high, but it will get less, thats normal
when will it get less?
after some minutes
Ws ping or api ping?
oh ok
ws
really? did you do client.ws.ping?
discord api is fine, but time taken to sent msg it high
There’s some deps you can install to reduce that, at least for production
can u pls tell?
z-lib will probably help
The page lists them all
can i install them all?
Sure
i tried rising the total shards, but i get an error every 2 or 3 seconds saying: 429 hit on route /gateway/bot after all this i changed the total shards back to 1, but it still does this error
?429-gateway
Warning : this only applies to 429's on gateway, for general 429 errors, refer to ?429
Getting 429 hit on route /gateway/bot when you add client.on('debug', console.log)?
Reasons :
§ You (or someone else) logged in 1000+ times in 24 hours. If you have auto restart on for your code upon crash, you know the culprit.
Are you using shared hosting like Glitch or Repl.it?
§ If yes, your IP has probably been banned by Discord, and theres nothing you can do rly except contact their support, or migrate to a better VPS.
Tip -> Temporary Cloudflare IP bans can last up to 1 hour. In case of IP ban, you can download your bot's code and host it locally.
§ If no situations above suits you, check Discord Status & contact Discord Support.
@terse cairn
oh no my ip has been prolly banned bc i am on repl.it ......
Yea, that’s the cons of shared hosting (shared hosting = shared ip bans)
self hosting sucks when your bot hits so many ratelimits
hi , there is problem in shard?
No specific one, or perhaps there isn't a problem with sharding, or discord.js' sharding capabilities. Unless you provide the error, maybe we could conclude there actually is one?
Error [SHARDING_READY_TIMEOUT]: Shard 0's Client took too long to become ready.
its was work but i do restart for my bot and the bot cant run
You might want to try to figure out why your client is taking longer than 30 seconds to ready. (Maybe the debug event could help?)
Or you could increase / disable the timeout.
https://discord.js.org/#/docs/main/stable/class/ShardingManager?scrollTo=spawn
the debug its
[WS => Manager] Fetched Gateway Information
URL: wss://gateway.discord.gg
Recommended Shards: 20
[WS => Manager] Session Limit Information
Total: 1000
Remaining: 0
[WS => Manager] Spawning shards: 0
[WS => Manager] Exceeded identify threshold. Will attempt a connection in 63486898ms
Oh, that'd explain it, you somehow managed to identify 1000 times within the last 24 hours.
maybe yes the bot was restart but what can i do now?
You can force a reset by commenting out this line (or the whole if block)
https://github.com/discordjs/discord.js/blob/12.5.3/src/client/websocket/WebSocketManager.js#L357
You then will receive a system DM from Discord and then have to generate a new token in the developer portal.
remove this line?
Yes, then you will exceed the limit.
thank you so much @marsh finch
Does sharding take up more ram and cpu usage?
Not much I can say there, you might also want to log the debug event of the client.
I don't really know, mostly if anything is off looking.
It shouldn't just stop out of nothing.
Why do I got unexpected token error for a \n in broadcasteval?
My snippet:
admin.send("${messageToSend}\n You got this message, because you're the admin of " + guild.name));
If I erase the \n it works good
You need to escape the \ there -> \\n
Thank you 🙂
how do you get the number of servers the bot is from the SHARDINGMANAGER?
<ShardingManager>.fetchClientValues('guilds.cache.size').then(r => r.reduce((a, count) => a + count, 0))
I'm not sure if guild would be defined, I think you need this.guild
no, with fetchClientValues everything isn't within a this keyword and is accessed directly from the client
Ahh nice to know
is there a shard ready event?
or only shardCreate event is present
there is a shard ready event, that's called <Client>#ready
(event) Client#ready
Emitted when the client becomes ready to start working.
oki
yes there is for the websocket shardReady
that's not a thing
to add on that, <Client>#shardReady is useful if a single client has multiple shards.
if you clients won't ever have multiple shards, then it's pretty much useless
are you sending your logs to a server channel?
no
is different ids everytime
that happens whenever you try to fetch a non-existing guild
thats normal? (if your listening for debug events) as type 13 is stage channels, and discord.js v12 dont support them so debug logs them as cannot find the channels type, new version only fix it not crashing
it is normal
all debug events are normal
the only things you should be watching out for is error events
debug isn't necessary if you're not experiencing a problem already
Any idea of how i can get each of my shards to show whether it's online or offline?
how do you mean? you'd like to report the shards' statuses?
const status = await <Client>.shard.broadcastEval(`
this.ws.status
`)
status[0] // the status of shard 0
you can also interchange Client with a ShardingManager
but access it at <ShardingManager>.broadcastEval instead
Not their statuses, to show whether a shard is online or offline
await <Client>.shard.broadcastEval('true', ShardToTest).catch(_ => false)
Perfect! Thank You Griefs!
@tough idol I don't suppose you know how to resolve the annoying [object Promise]?
resolve it how? context please
What i have is in the following screenshot, although when i go to run the command i get the [object Promise] response.
it needs to be awaited
broadcastEval returns a promise
Cheers.
Hey! Not sure if this is the correct channel, but I have a little question. I am currently trying to get the ShardingManager to work with TypeScript. I am also using the master Branch, however I don't think this has anything to do with my Issue:
When trying to run the bot TS file itself, it works perfectly fine. But when running it through the ShardingManager, I get an error saying that an import Statement cannot be used outside a module. Does anyone know what causes this Issue or does anyone here have any example on how to use ShardingManager with TS?
you cannot use import if the file is not .ejs or not a declared ESM
you can declare a file as an ESM in package.json
Could you explain further?
i think you're trying to import a JavaScript file, but JS realising that the imported file is not an ESModule
I am not working with JS files at all. I am using ts-node... (Nodemon actually, but that runs TS Files through ts-node)
but you're importing discord.js. that's javascript
does it include a stack trace?
Yes, but discord.js has Type Definitions, doesn't it? And importing discord.js itself in my file with the Shard Manager works. But having any import statement in the file of the actual bot/client doesn't.
what's the filename of your shardingmanager and client?
My ShardingManager is ./launcher.ts and my Client is ./src/bot.ts
try renaming bot.js to bot.ejs in the compiled version
just to narrow down the issue
Again, there is no compiled version.
then compile it, tse relative/path/to/folder
(or well there might be, but not as files - I don't know how exactly ts-node works behind the scenes)
(node:21520) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
A:\Development\bot\src\bot.ts:1
import * as dotenv from "dotenv";
^^^^^^
SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:979:16)
at Module._compile (internal/modules/cjs/loader.js:1027:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
This is the error I recieve by the way. I already tried setting the type to module in the package.json, which didn't fix the issue.
edit your tsconfig compilerOptions.module and set it to "commonjs" to use CJS modules instead
Already seen that on SO and did exactly that. Doesn't change anything (in regards to my issue).
Hey guys,
I'm having trouble requesting emojis across shards. I already got the emoji object via broadcast, but I don't get a GuildEmoji / ReactionEmoji type, which I need to be able to react with it.
Do you have a solution for me?
https://img.namespace.media/images/2021/06/01/WindowsTerminal_X8qHWRZKHL.png
This object should be the right one right?
did you try renaming the bot.js to bot.ejs?
compile and show the bot.js code
I am having some errors caused my discord.js when trying to manually compile...
what errors?
(way more stuff, basically pretty much the same)
ts and djs version?
Don't really know how to find out the TS Version 😅 Unless a new one released within the last 20 minutes, I'm on the newest stable version though.
DJS Version is 13.0.0-dev.7f0d93a2dacf07b39c358b2cf2f5519a757e43b5
what's the command you ran?
To compile?
yeah
ts bot.ts from inside the src Folder
66a6a1fcedc8c35b75a89dbb26edc01317bdd7e2 is the latest commit. this hsould be in #djs-help-v14 btw
Well, this issue doesn't seem to have anything to do with any changes in DJS13 though, does it? If you take a look at my original message and the output I sent a bit above, this is an error coming from TypeScript which occured when running through ts-node. The other issues above only occurred after trying to compile the TS files manually for debugging purposes.
do tsc -v
4.0.3
djs' typescript is 4.3.2. but i don't think there's any major changes for that to occur, considering it's the same version
Do you by any chance know any open source bots which use Sharding and TS I could just take a look at for reference?
You need typescript 4.1+
Alright. That fixes compiling. Not sure yarn installed an outdated version 20 minutes ago. I compiled the client file itself to a JS file now. What exactly should I do with that now?
Edit: Also, that compiled file does not use import Statements, but require, so I assume the Issue lies somewhere when running the thing through ts-node
someone got an idea?
show the code
rename bot.js to bot.ejs
ejs? i means mjs
and then run at entrypoint via node
What exactly do you mean by that?
node shardmanager
So I should compile the file with my Shard Manager to JS as well?
oh yes, compile the whole thing
what does it mean when my shards keep delaying the connection?
the sharding manager has a delay of 5.5 seconds yet when I launch a lot of shards, they all keep requeueing
Then gives me a completely different error of exports not being defined in bot.mjs (exports.__esModule = true;; which is code generated by the TS Compiler)
yeah that's normal
rename it back and run entrypoint through node