#archive-sharding

12465 messages · Page 3 of 13

terse cairn
fiery hornet
[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}`));
little bluff

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?

lusty smelt

How much is the maximum amount of total guild count internal sharding can handle?

Its likely ideal upto 32K i think

little bluff
lusty smelt
lusty smelt
lyric lantern

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 to discord.js/src/client/Client.js:425:17

What did I do wrong?

crimson pond
lyric lantern
crimson pond 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]

lusty smelt
[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 Thonk

crimson pond
next plaza
wet topaz

1/5? that doesn't sound right

lyric lantern
crimson pond
fervent zealot

.

pallid spindle

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)

next plaza
young totem

How can I make a rolling restart on my shards?
To clarify, restart one shard at a time to minimize downtime when making changes

wet topaz

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

young totem

so that would make that sharding client restart that shard? when it detects it went offline?

wet topaz

sharding manager restarts processes when they exit, yes

young totem

sounds good, ty!

terse cairn
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

terse cairn

?sharding

icy crowBOT
wet topaz

that... is not what shard is

also, are you getting any errors? anything?

can't pull out answer out of thin air

terse cairn
wet topaz

what are you running

terse cairn

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

wet topaz
  1. this is not how that works. shard isn't client
  2. use spawn() instead of calling createShard n times

what command are you using to start

terse cairn

a command to start..?

wet topaz

yes

that code doesn't run on its own

you have to start it

terse cairn

OHHH so that's the problem, i don't have any command to run it

wet topaz

wat

did you even attempt to start your bot

terse cairn

yes i did.

wet topaz

how

terse cairn

the bot runs perfectly, the problem is that the shards doesn't get created

wet topaz

how do you start it

terse cairn

with the button "start", i use replit

wet topaz

fairly sure that that button starts main file

which in 99.9% of cases is index.js

terse cairn

mmm

next plaza
terse cairn

ok now, it works, but, now express throws error, 'Port 3000 is already on use'

broken sequoia

not djs

terse cairn

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.
terse cairn

someone?
:c

jade venture

Is there way to check if all shards has spawned?

wet topaz

@terse cairndon't run the server in index.js but in manager file.

jade venture

Is it possible to "build" Client from array? (Using broadcastEval)

terse cairn

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

wet topaz

code?

terse cairn
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);   
    }
});
wet topaz

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

terse cairn

yeah but i need to eval things

i don't care what's going on inside shard

wet topaz

then eval them in ready

terse cairn

uhmm how

wet topaz

?

terse cairn

how do i get client ready event if it's "inside" shard

wet topaz

the regular ready event on the client

in the file your manager spawns

terse cairn

i have to do it outside, not inside bot

wet topaz

why exactly?

terse cairn

because of how bot built

wet topaz

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

terse cairn

i don't need messages or anything inside, just some thing

i'm hosting web api for it outside

wet topaz

from what i can see above, all you do is log commands

terse cairn

i can't make web server run 50 times inside every shard

wet topaz

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

terse cairn

thinq
i don't quite get it

wet topaz

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

terse cairn

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

wet topaz

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

terse cairn

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

wet topaz

no, not really

terse cairn

i just need to get 1 variable from the first shard that will connect

wet topaz
terse cairn
wet topaz

are we really going to do that

terse cairn

lol, i just don't think it's necessary

a harder way of doing things

wet topaz

not harder, but proper

it's really not hard to run a single websocket server

terse cairn

what's wrong with evalling things with sharding manager

wet topaz

why are you even evaling command list

terse cairn

because i need it for stuf

wet topaz

then read the directory

terse cairn

commands are inside the module files

wet topaz

then read the files

terse cairn

mfw running huge ass slow files that take 10 seconds to run just to get command list

wet topaz

you do it 50 times anyway

terse cairn

it was an example
and still, bad thing

why running for no reason

wet topaz

ok then

go ahead and use your eval

terse cairn

(it doesn't work which was the original issue)

wet topaz

and any other monkey patched solution

see

this is why i suggested multitude of things

terse cairn

but why it calls create event before it's created??

wet topaz

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

terse cairn

it would work perfectly if i got event smething like "shardLoaded"

wet topaz

it's called ready in client

terse cairn

gsjhgsdjkhd, yeah whatever

wet topaz
terse cairn
wet topaz

yes

because

and only later it awaits all promises from spawning

terse cairn

everything would be 5 times easier if event like that existed RoflanZachto

wet topaz

dude

why are you so opposed to using ready event

terse cairn

because have to make a server just for 1 (one) thing

wet topaz

no, you don't have to

terse cairn

wait is there way of communicating with sharding manager

wet topaz

you can even console log it

and read from stdout

and yes

terse cairn

gg

i have 549045903 of different stuff in console log

wet topaz

and === or startsWith() don't really care

shrugCat

terse cairn

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

winged bobcat

You could have listened to the shard ready event

That gets emitted after the client

mental tinsel
    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?

winged bobcat

?shardreadytimeout

icy crowBOT

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.

teal plume

Could someone send me an initial bot for me? to train some things without a bugs

wet topaz

?guide

icy crowBOT
terse cairn

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

sturdy ember

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

wet topaz

You could always try

terse cairn

how to get the shard ping?

next plaza
next plaza
terse cairn
next plaza
terse cairn

ok

stiff mason

what would cause this

marsh finch

As the string mentions, Discord wants you to reconnect every (15 min - 4h) to balance the load on their end.

stiff mason

oh

minor sapphire

I was wondering about shards. My bot isn't completely huge, but what is the benefit of shards, and what are they used for?

dense cape
golden moss

You wanna use it before you hit 2500 because its required by discord at that point.

dense cape

Discord requires you to do it at 2500 guilds

It distributes the load of events across how ever many shards you have

golden moss

Is there a way to get the whole GuildMemberRoleManager#cache from broadcastEval? @dense cape

dense cape

You can, but it would be a plain object

golden moss

Would I not be able to call .get()

dense cape

No

Collection would be converted to an array of arrays

golden moss

hmmm

dense cape

What are you trying to achieve?

golden moss

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

dense cape

So you need to list the roles, then be able to get a role on command?

golden moss

Yes

dense cape

Are these actions separate endpoints?

golden moss

No

dense cape

You could just throw the array of arrays back into new Collection/Map, then get the role data

golden moss

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?

dense cape

The former

golden moss

Why do I not know what former means all of a sudden in this context

broken sequoia

First mmLol

golden moss

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

dense cape

Show code

golden moss
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)
dense cape

broadcastEval still returns an array of data

golden moss

Oh wait

dense cape

One item for each shard return data

golden moss

But it would only return one set so I need to do roles[0] when I pass it

dense cape

Yea

golden moss

Lets see

Both collections still empty?

console.log(roles[0])
    roles = new Collection(roles[0])
console.log(roles)

@dense cape

dense cape

Huh, it returned an array

You could do [...<Map>] in the eval

golden moss

Where?

dense cape

In the eval

Instead of calling toJSON, wrap the Collection in an array and use the spread operator

golden moss

I don't follow sad

golden moss

remove the .toJSON() and switch it with?

dense cape
golden moss

Yes

dense cape

If you do [...<Map>], it’ll return an array of entries [key, value] that can be easily converted back to a Map/Collection

golden moss

Why is my brain breaking

dense cape

[...<Guild>.roles.cache]

golden moss

ahhhh

dense cape

You would have to add a check to make sure the guild is found tho

golden moss

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

dense cape

Yes

golden moss

Is that right?

pallid depot

Error [SHARDING_READY_DIED]: Shard 0's process exited before its Client became ready.

pallid depot
sudden sequoia

did the tags solution not fix it?

tawny silo
sudden sequoia

hmm, try that i guess

tawny silo
sudden sequoia

can you show your sharding file?

tawny silo
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);```
sudden sequoia

wait a min

tawny silo
tawny silo
sudden sequoia
shards.spawn(1, 1000, -1);

can you try this?

tawny silo

sure

sudden sequoia

ping me with the response 👍

tawny silo

no response

its just stuck

tawny silo
sudden sequoia

hmmm

¯_(ツ)_/¯

tawny silo

...

sudden sequoia

now i am out of ideas why, you would have to wait until some one who knows about this comes

wet topaz

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?

terse cairn

His question has been answered in a different channel, he has to wait out a 15 hour too-many-logins cool down

wet topaz

i love channel hoppers.

terse cairn

why does my bot respond two times

nvm i fixed it

thin trench

Is there a way to have per shard status? So each shard has their shard number in their status

dense cape

?docs ClientUser.setActivity

icy crowBOT
dense cape

Use options.shardID

pallid depot

How to define shard in other files

lean scarab

?help

icy crowBOT
lean scarab

?docs Intents

wet topaz
graceful juniper

hello , who can help me with sharding? ty

wet topaz

guide can

high sequoia

whats the benefit of sharding?

wet topaz

splitting load that is eventually enforced on you

high sequoia

so bot goes faster?

wet topaz

no

not raelly

it more prevents it from slowing down, since one shard only handles some of the guilds

graceful juniper
wet topaz

guide

graceful juniper

I saw it, but still need help

wet topaz

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

graceful juniper
jagged fjord

zajW i was acting stoopid for like idk a long time

wet topaz

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

graceful juniper

Do not really understand in shard

wet topaz

sharding spawns copies of your main file

your main file handles commands and events and all that

graceful juniper

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();
wet topaz

yes

graceful juniper

ok , Thank you very much

next plaza

it is not recommanded to spawn manually new shards, use the method #manager.spawn(shard_count, spawn_delay, timeout)

yes, so whats your question?

mortal matrix

How does one get information on their bots shards? (Viewing how many guilds in said shard, viewing if shards are down etc etc)

potent tendon

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
broken sequoia

Yes, it isn't defined in the sharding file

potent tendon

What should I add in the sharding file?

Or what can/should change?

mortal matrix

How does one get information on their bots shards? (Viewing how many guilds in said shard, viewing if shards are down etc etc)

waxen hill

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.

potent tendon

I know, my main file has code in aoi.js, see the msg above pic.

graceful juniper

I nees to start the shard file and not the main file ?

pallid depot

Yes

graceful juniper

Ok

All shards ? @terse cairn

graceful juniper

client.shard.count

Ah

potent tendon

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.

graceful juniper

What i need to put here ?
In the "()"
manager.spawn();

pallid depot
potent tendon

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.

pallid depot

blobguns

graceful juniper

Anyone know why I get a high ping in shard?

pallid depot

On host or selfhost ?

graceful juniper

Host

But , i try 2 other hosting , and same ping ( high ping )

pallid depot

Maybe you didn't choose the right server !

graceful juniper

Believe me I chose the right server lol

prisma jewel

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

graceful juniper

What i need to put here ?
In the "()"
manager.spawn();

OK

prisma jewel

Yeah, those are all 3 params

?docs ShardingManager

icy crowBOT
graceful juniper

And anyone know why I get a high ping with shard?

prisma jewel

it can actually hinder performance normally sometimes

graceful juniper

My bot is on 740+ servers, and there are bots on about 100 servers that do shard and nothing happens

prisma jewel

sharding does use excessive amounts of memory

I'd recommend a VPS provider with an unmetered plan.

icy crowBOT
iron solstice
next plaza
iron solstice

i know that, but how is a music bot any different?

strange echo

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

next plaza
iron solstice

oh ok, so is it recommended for music bots to shard earlier?

potent tendon

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?

wet topaz

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

potent tendon

Okay.

And what's wrong here?

graceful juniper

anyone know why I get a high ping with shard?

next plaza
white crane

Hi guys, what would the limiting factors for the size of internal sharding be? Is there an established estimated limit to it?

dense cape

Ur cpu would be the main limiting factor

Bc internal sharding runs multiple ws on one cpu/process

young totem

Can I run code in ShardingManager simlar to with broadcastEval?

young totem

Sorry to bump but it's been a while. Anyone able to help?

wet topaz

what do you even mean

young totem

from a shard, run code with access to the shardingmanager and its functions/properties

in the parent process

wet topaz

what are you trying to do

young totem

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)

young totem

yes but I want to do it one at a time so I can’t use restartall

prisma jewel

I have a question. So how would I pass data from my database into the separate shards

dense cape

Ur shards should be fetching from the db

@prisma jewel

tropic rose

the ready event is only fired when all shards are ready, right?

marsh finch

All shards handled by the emitting client, clients in other processes / workers do not count here.

lyric lantern

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

next plaza

thats normal that internal shards reconnect and resume, it can be bc of the internet connection or sometimes DIscord closes the connection.....

welcome

prisma jewel
potent tendon

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?

terse cairn

How can i map all of the shards?

prisma jewel
next plaza
prisma jewel

@next plaza Does .fetchClientValues() work with something like this

next plaza
prisma jewel

thats in the client's module.exports, so I assume so

and it extends discord.client

So @next plaza this should work?

prisma jewel
next plaza
next plaza
prisma jewel
next plaza
prisma jewel

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

prisma jewel
next plaza

you can inject some code and overwrite properties, but this will break the libary

prisma jewel
next plaza
prisma jewel
next plaza
prisma jewel

i have a database already

next plaza

yes, you can run the database an all shards

on the bot instance itself

prisma jewel

Alright, thanks

young totem
prisma jewel

?docs shard

icy crowBOT
young totem
prisma jewel shard.respawn(shardID)

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.

prisma jewel
young totem
prisma jewel

I forgot that shardingmanager existed lol

young totem

Yes, I'm trying to send a message from a shard to that process to run the code for the restart.

prisma jewel

?docs shardingmanager

icy crowBOT
young totem

waitwhat

prisma jewel

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

young totem

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.

prisma jewel

I think if you wanted to restart a specific shard, you could just simply kill the shard

shard.kill

and it will respawn

young totem

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.

prisma jewel

manager to shard or shard to manager

young totem

shard to manager

next plaza

this will send a message to your sharding manager and you can listen on it with manager.on('message')

prisma jewel

Ahhh, I knew I was forgetting something, .send is your best bet

young totem
prisma jewel

@next plaza I meant to ask you, if I wanted to index the database on the shard would I just do client.shard.db?

icy crowBOT
prisma jewel

There should be documentation from there

young totem
prisma jewel ?docs shard#send

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.

next plaza
next plaza
prisma jewel

client.db returns null

next plaza

on worker_threads you cant bc of the structured cloning algorithm, you have to stringfy them first

young totem
young totem

Got it, thanks for your help!

next plaza
prisma jewel
next plaza

it comes up, where you load it, on which variable

prisma jewel

its in my client.js under client.db = require('./utils/db.js'), however client.db returns null

prisma jewel

this

next plaza
prisma jewel

last 4 lines export settings and users

which are the 2 data tables

next plaza

and when you broadcast (this.db), it returns null?

prisma jewel

client.db, as its in a client.on('guildMemberAdd', async(client, member) => {})

next plaza
prisma jewel

filesync

next plaza

and why is it client.on ?

prisma jewel

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;
  }
next plaza
prisma jewel

guildMemberAdd.js

next plaza

it should be

module.exports = async(client, member) => {
}
prisma jewel

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

next plaza
prisma jewel

the same way you said

terse cairn

hey @crisp coyote, why did you remove <ShardClientUtil>.ids in kurasuta?

misty cosmos
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?
dense cape

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

misty cosmos
dense cape

You’ll want to return the top 10 guilds from each shard

terse cairn

it should be an array

crisp coyote

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

terse cairn
sweet lantern

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?

terse cairn

@crisp coyote Is there a support server for kurasta?

Because my friend encountered an issue using the clustering package

next plaza
terse cairn

Ahh okies

broken sequoia
terse cairn

Hi

I’ve a question

What’s shards ?

glossy bluff

Instances

prisma jewel
terse cairn What’s shards ?

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

prisma jewel

So is .send a valid method to use to send data to the shard

or only data from the shard.

echo fulcrum

Can ShardingManager actually run typescript file?

it return SyntaxError: Cannot use import statement outside a module when running the typescript file

next plaza
serene hill

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
serene hill
fathom hamlet
serene hill

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
fathom hamlet

idk

echo fulcrum
next plaza
serene hill ohh
const Discord = require('discord.js')
or 
const { Intents, ShardingManager } = require('discord.js');
new ShardingManager....
next plaza
echo fulcrum

how can i do this ?

serene hill

so now i have 0 shards so how can we increase it?

broken sequoia

no, and its not related to sharding nor djs

trail monolith

Is the shader hard to use?

next plaza
next plaza
willow steeple

Why is the timeout 30s for shard respawning? why doesn't it take the initial spawn timeout value?

prisma jewel
rough bone

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

wispy ocean

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)

spare imp

@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

wispy ocean

alright ty

terse cairn

How do we get the number of shards from broadcastEval?

wispy ocean
sudden sequoia

and what does that have to do with sharding ?

robust mountain

just awesome help...

serene hill
prisma jewel
serene hill
prisma jewel

It won’t let you launch more shards then you have guilds

glacial basalt

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

glacial basalt
{"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?

winged bobcat

Cant, instead reduce and add the values from the fetchClientValues Promise array

glacial basalt

okay

winged bobcat
manager.fetchClientValues('guilds.cache.size') .then(results => console.log(`${results.reduce((prev, val) => prev + val, 0)} total guilds`)) .catch(console.error);
glacial basalt

Ty

winged bobcat

Np

sharp scroll
glacial basalt

can anybody help me?

dense cape
glacial basalt

(error)

glacial basalt
dense cape

Code?

glacial basalt
dense cape 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)}`)
})```
dense cape

guildCreate gives you a guild, not a client

glacial basalt

oh right, but than how would I do it?

dense cape

Prob shouldn’t be updating a channel with live data like that tho, the rate limits are pretty hefty

glacial basalt
dense cape

And when it does?

glacial basalt

I guess you're right...

How about making it update in an interval? @dense cape in a ready event (such as every hour ext...)?

dense cape

I guess that’s fine

glacial basalt

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

dense cape

The interval should be made in the manager file

glacial basalt
dense cape

No, but you can tell the shard to update the channel

glacial basalt

right

steady nimbus

There is a way that if the Shard collapses it will reignite

wet topaz

it does that by default

steady nimbus

@wet topaz so why sometimes the Shard collapses on me and never comes up again

next plaza
terse cairn

how can i access a node module inside of broadcastEval?

tacit spoke

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?

terse cairn

UnhandledPromiseRejectionWarning: #<Response>
pain

winged bobcat
terse cairn

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
terse cairn

pls help

echo fulcrum

how can i kill all the shards that created from the sharding manager?

winged bobcat

?docs ShardingManager#shards

icy crowBOT
steady nimbus
dense cape

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

prisma jewel

so a larger issue still, I can't seem to pull from my database on shards, I use better-sqlite3

rain mica

Hi. I'm sharding my bot with typescript, and get this error

Also I extend Discord.ShardingManager class, if it matters

static tusk

XD

next plaza
rain mica
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

next plaza

your sharding manager file

rain mica
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 ^^

terse cairn

When doing using djs' way to set shards to auto. Do I set auto as string?

dense cape

Yes

terse cairn

What do I need to change in my codes (command etc.) if I add shard to my bot

stoic remnant

there's a guide on it, check the d.js guide

terse cairn
stoic remnant
terse cairn

Ty

glacial basalt

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

humble shadow

is there a way i could check if any of my shards are down without the event?

prisma jewel

?docs ShardingManager

icy crowBOT
sudden sequoia

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

terse cairn
coral urchin
terse cairn
coral urchin
terse cairn

i know absolutely nothing about sharding

spice frost

(node:119388) UnhandledPromiseRejectionWarning: Error [SHARDING_READY_DIED]: Shard 1's process exited before its Client became ready.
Any idea?

terse cairn

your sharding code?

spice frost
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

marble maple

try addind mode to the options

spice frost

mode?

terse cairn

maybe to -1

stray night

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?

spice frost

I tried process but still throws the same error, worker throws another canvas error for some reason

regal oriole

what am I doing wrong?

🤔

winged bobcat

Thats the wrong method

winged bobcat

Use that

icy crowBOT
regal oriole
winged bobcat

Np

regal oriole

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...

dense cape

Send inside of the eval

regal oriole

omg thanks

dense cape

Why are you getting the user via broadcastEval? Is this being called from the sharding manager?

regal oriole
dense cape

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

regal oriole
dense cape

Both shards can have the user as well

regal oriole
dense cape

Could also be none

regal oriole

otherwise returns null

ok, maybe im wrong...

dense cape

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

regal oriole
regal oriole
dusky osprey

Can someone link me an extremely detailed resource to what sharding is. I tried googling but didn't understand much

lusty smelt

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)

next plaza
lusty smelt
timber roost

How can I put the current shard id to the bot's status?

next plaza
lusty smelt

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?

lusty smelt
marble maple

for stickers u have to extend message afaik

timber roost

Then how can I find the id of the shard the current process is on?

next plaza
next plaza
lusty smelt

Rip

next plaza
lusty smelt 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

lusty smelt

perhaps moving to traditional sharding will help?

marble maple

just asking which mode do u use?

next plaza
lusty smelt
marble maple
next plaza
lusty smelt

those are internal shards, websocket shards

marble maple

hm

lusty smelt

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

next plaza
lusty smelt

stable branch, right?

timber roost
next plaza
next plaza
timber roost

How can I do that inside the shardCreate event?

next plaza
timber roost

But how am I supposed access the shard id that way?

marble maple

is the only shardCreate event only?

imean how many events are there for the sharding manager

next plaza
timber roost

I didn't know that existed, thanks!

lusty smelt
next plaza yes

Well upon comparison, I dont see any major changes that would be the cause of the issue

next plaza
lusty smelt

o

proud bridge
abstract elm

How would i get information of each shard i.e each shard's ping etc

radiant sail

what even is a shard, never heard of them until i read the docs but there was no explanation lmao

terse cairn

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.

radiant sail

oh, don't need that my bot is trash lmao

lucid musk

Hi, How to use the shardIDForGuildID method

dense cape
lucid musk

Oh, thanks

Why does it return an error?
this.client.shard.shardIDForGuildID(${message.guild.id}, ${this.client.shard.count})

lucid musk

TypeError: this.client.shard.shardIDForGuildID is not a function Thonk

dense cape

It’s a static method

ShardClientUtil.shardIDForGuildID(…)

lucid musk

Thanks sharkHi

next plaza
lusty smelt

ty 😄

quick plinth

how can I get the ID of a shard from within the shard

marble maple
quick plinth
marble maple

try ids

abstract elm

How would i get information of each shard i.e each shard's ping, etc?

marble maple

something like this should help

abstract elm
marble maple

ehhh

i think remove ping[9]

abstract elm
marble maple

use await ofc

try a async function

abstract elm

yep

marble maple

mhm now i gtg

abstract elm

Odd.

marble maple

ofc it’ll be odd u have to call that function

round vale

?sharding

icy crowBOT
abstract elm
marble maple

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

abstract elm
marble maple

this will make sure ull not get promise's

abstract elm

Right. Okay.

abstract elm
marble maple
abstract elm

Thought i did. Though like I previously said, returns the Promise part of which I'll fix when im next on pc.

marble maple

yes then ull to fix the promise part

then itll show results 😄

abstract elm

Oh, great.

I'll sort that out, now.

@marble maple You're a star, thank you!

marble maple

np : )

robust zenith

is there anyway to speed up bot launching with multiple shards?

lyric lantern

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?

tough idol

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

celest grotto

Hello , i sharding my bot and i dont know how to send a embed in a custom channel :(

terse cairn

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

celest grotto
terse cairn

Well you shouldn't call it on null

You can only use client.shard if the process was spawned from a ShardingManager

celest grotto

poggies nice

terse cairn

How did you shard your bot?

celest grotto

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!`)

})```
icy tree

If you plan on running the bot on one server do I need to shard my bot?

restive vortex

sharding is for bots in 2500+ guilds

next plaza
spice frost

(node:86) UnhandledPromiseRejectionWarning: Error [SHARDING_READY_TIMEOUT]: Shard 0's Client took too long to become ready.
any idea?

tawny silo

@spice frost client.on('warn', console.log)
client.on('debug', console.log)

then show me the output

fringe barn

can anyone help me with enmap database? it works well but not the bot is running in shards

terse cairn
loud badger

Hey all, what's the benefit of sharding

iron sorrel
loud badger

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

marble maple

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

unkempt onyx

I used the sharding from the guide, but im still getting multiple responses for one command, how can i fix this

tough idol

did you follow the guide to-point? your code matching the guide with nothing extra?

unkempt onyx

Nothing extra and nothing less, it launches two shard #0 tho i dont know why

tough idol

are you using a process manager? like pm2?

unkempt onyx

How would i know?

Cause I've never used any package like that

tough idol

do you use node in command-line, like node index.js

unkempt onyx

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

tough idol

of course.
check these:

  1. accidentally running the process twice?
  2. accidentally accessing your bot's entrypoint from shard manager entrypoint?
unkempt onyx

How do i check the second

tough idol

does the file that contains ShardManager access (require) the file that logs into discord?

unkempt onyx

Yes

tough idol

that's bad

show me the line where you're requiring it and where you're using it

unkempt onyx

But thats what the guide had, unless i need to remove the client.login from my main file

unkempt onyx
tough idol

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

unkempt onyx

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?

tough idol

erm, you're not requiring it.

that's correct

unkempt onyx

ok thanks alot man

tough idol

that should work fine

tough idol

yes

unkempt onyx

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

tough idol

that shouldn't affect it

unkempt onyx

this happens

tough idol

would you like to take this to DMs? i feel like troubleshooting this will clog up the channel

stiff mauve

@terse cairn

on the client file (the file where your ShardingManager ISN'T located) are you logging in?

terse cairn
stiff mauve

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)

marble maple
terse cairn

Will djs support clustering in the future?

terse cairn

why is sharding rising my bot ping soo much?
like my bot ping now is 2000+

tough idol

that shouldn't be the fault of djs.
an unoptimised database handler could be the problem

next plaza
terse cairn
next plaza
dense cape

Ws ping or api ping?

terse cairn

oh ok

terse cairn
next plaza

really? did you do client.ws.ping?

terse cairn

discord api is fine, but time taken to sent msg it high

dense cape

There’s some deps you can install to reduce that, at least for production

next plaza

z-lib will probably help

dense cape

The page lists them all

terse cairn
dense cape

Sure

terse cairn

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

dense cape

?429-gateway

icy crowBOT

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.

dense cape

@terse cairn

terse cairn
dense cape

Yea, that’s the cons of shared hosting (shared hosting = shared ip bans)

tough idol

self hosting sucks when your bot hits so many ratelimits

wooden lance

hi , there is problem in shard?

stoic remnant

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?

wooden lance

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

marsh finch
wooden lance

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
marsh finch

Oh, that'd explain it, you somehow managed to identify 1000 times within the last 24 hours.

wooden lance

woah maybe yes the bot was restart but what can i do now?

marsh finch

You then will receive a system DM from Discord and then have to generate a new token in the developer portal.

marsh finch

Yes, then you will exceed the limit.

wooden lance

thank you so much @marsh finch

fervent dragon

Does sharding take up more ram and cpu usage?

marsh finch

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.

lyric lantern

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

marsh finch

You need to escape the \ there -> \\n

lyric lantern
true swift

how do you get the number of servers the bot is from the SHARDINGMANAGER?

tough idol
terse cairn

I'm not sure if guild would be defined, I think you need this.guild

tough idol
terse cairn

Ahh nice to know

marble maple

is there a shard ready event?

or only shardCreate event is present

tough idol

there is a shard ready event, that's called <Client>#ready

proud mortarBOT

djs (event) Client#ready
Emitted when the client becomes ready to start working.

marble maple

oki

next plaza
tough idol

that's not a thing

tough idol
tough idol

are you sending your logs to a server channel?

terse cairn

no

is different ids everytime

tough idol

that happens whenever you try to fetch a non-existing guild

sudden sequoia

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

tough idol

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

abstract elm

Any idea of how i can get each of my shards to show whether it's online or offline?

tough idol

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

abstract elm

Not their statuses, to show whether a shard is online or offline

tough idol

await <Client>.shard.broadcastEval('true', ShardToTest).catch(_ => false)

abstract elm

Perfect! Thank You Griefs!

@tough idol I don't suppose you know how to resolve the annoying [object Promise]?

tough idol

resolve it how? context please

abstract elm

What i have is in the following screenshot, although when i go to run the command i get the [object Promise] response.

tough idol

it needs to be awaited

broadcastEval returns a promise

abstract elm

Cheers.

paper obsidian

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?

tough idol

you can declare a file as an ESM in package.json

paper obsidian

Could you explain further?

tough idol

i think you're trying to import a JavaScript file, but JS realising that the imported file is not an ESModule

paper obsidian

I am not working with JS files at all. I am using ts-node... (Nodemon actually, but that runs TS Files through ts-node)

tough idol

but you're importing discord.js. that's javascript

does it include a stack trace?

paper obsidian
tough idol

what's the filename of your shardingmanager and client?

paper obsidian

My ShardingManager is ./launcher.ts and my Client is ./src/bot.ts

tough idol

try renaming bot.js to bot.ejs in the compiled version

just to narrow down the issue

paper obsidian

Again, there is no compiled version.

tough idol

then compile it, tse relative/path/to/folder

paper obsidian

(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.

tough idol

edit your tsconfig compilerOptions.module and set it to "commonjs" to use CJS modules instead

paper obsidian
hollow badge
tough idol

compile and show the bot.js code

paper obsidian

I am having some errors caused my discord.js when trying to manually compile...

tough idol

what errors?

paper obsidian

(way more stuff, basically pretty much the same)

tough idol

ts and djs version?

paper obsidian

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

tough idol

what's the command you ran?

paper obsidian

To compile?

tough idol

yeah

paper obsidian

ts bot.ts from inside the src Folder

broken sequoia
paper obsidian
tough idol

do tsc -v

paper obsidian

4.0.3

tough idol

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

paper obsidian

Do you by any chance know any open source bots which use Sharding and TS I could just take a look at for reference?

bright lynx

You need typescript 4.1+

paper obsidian

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

tough idol

rename bot.js to bot.ejs

ejs? i means mjs

and then run at entrypoint via node

paper obsidian
tough idol

node shardmanager

paper obsidian

So I should compile the file with my Shard Manager to JS as well?

tough idol

oh yes, compile the whole thing

willow steeple

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

paper obsidian
tough idol

yeah that's normal

rename it back and run entrypoint through node