#archive-sharding

12465 messages · Page 11 of 13

nimble mist

Don’t require your client anywhere or export it from the main file. Almost every object in djs has a client property where you can get it from anyway

real stag
terse cairn

show ur code

dense cape

Make sure it's prefixed correctly and ur using the user's access token

real stag
real stag

and here I'm requesting the token in login.js

lost hatch

I'm manually respawning the WebsocketShard
ohh boy, I went through it too. The pr would help you with it 😄

btw I wrote a script to replace the files in node_modules/discord.js with the code in pr. I just set it up once and respawn all of them. Works fine so far. There is a better solution to it, I will have that pushed in my pr in few days and then merge it into main

slim mortar

figured I'd ask here as it's related to multi process bots
any way to share rate limit data between the bots? if one process hits a rate limit I don't want another process to then hit 429s that could've been prevented
was thinking some redis thing but honestly no clue where I need to look

dense cape
slim mortar

I'll put that on some imaginary list for next year then

or whenever it happens

lost hatch

Hopefully with new ws module of vlad, Ig he will cover this in it

terse cairn
const Discord = require('discord.js');
const { SlashCommandBuilder } = require('@discordjs/builders');
module.exports = {
  data: new SlashCommandBuilder()
    .setName('pp')
    .setDescription('p!')
    .addBooleanOption(option => option
      .setName('reply')
      .setDescription('reply؟'))
  ,
  execute(interaction, client, retEph) {
    try {

      let embed = new Discord.MessageEmbed()
      // ...
      
        interaction.channel.send({ embeds: [embed] }).catch((err) =>console.log("Err-PP: " + err));
      

 } catch (er) {
      console.log("caErr-Pray: " + er)
    
  },
};
``` the bot send 5 messages!! how to fix it

also in guildCreate event it send 5 messages

sometimes 2 or 3

slim lintel
terse cairn

could it be because of replit?

slim lintel

Possibly, do you have any sharding or anything running?

Ah wait, stupid question we’re in the sharding channel, unless you just crossposted

terse cairn

3 i think

terse cairn

FHDN

half vessel
nimble mist
half vessel

I don’t, I don’t even use sharding, but this suggested that they’re bot was being hosted on replit and it was using sharding, I suggested an idea for them which im not sure would work because i’ve never been in a scenario like that

nimble mist

Oh, I totally missed that message mentioning replit. My bad🤦‍♂️

nimble mist
iron zodiac

okay so my bot requires tonna user response from messages, Since message content is being phased out im using DMs for that, But since all user DMS are on shard 0 the so the "MessageCollector" only really works with commands that are initiated on guilds that are on shard 0, Anyway i can get MessageCollector work in shards other than 0 in DMs

slim lintel
terse cairn
const manager = new ShardingManager('./bot.js', {
  token: process.env.token
});``` this will work fine
const manager = new ShardingManager('./bot.js', {
  totalShards: 2, // !
  token: process.env.token
});

manager.on('shardCreate', s=> console.log(`Launched shard ${s.id}`));
``` but this will spam the console
terse cairn

Probably because of replit

nimble mist

Yup, your shards get respawned quite often because of replit instability

bitter shadow

Had this issue today where a shard would receive no heartbeat in time and destroying the shard and reconnecting but after this message here I did not receive any heartbeat from shard 12 ever again https://i.altpapier.dev/M4bs0mwWfU.png . I had a look with ws.status and ws.ping but ws.status shows 0 for READY and ws.ping shows the same ping every single time I try and ping it. Any idea how this issue can be solved to not happen in the future?

serene shell

how do i get the total number of voice channel connections across all shards?

vale basin

require("dotenv").config();
const { ShardingManager , Client} = require("discord.js")
const colors = require("colors")
const shards = new ShardingManager("./index.js" , {
  token : process.env.token,
  totalShards : "auto",
  respawn : true,
  delay : 20000,
  timeout : 60000
})
shards.on("shardCreate" , async (shard) => {
  console.log(`[${new Date().toString().split(" ", 5).join(" ")}] Launched Shard #${shard.id}`.bold.green)
})

shards.on("disconnect" , async (shard) => {
  console.log(`[${new Date().toString().split(" ", 5).join(" ")}] Disconnected Shard #${shard.id}`.bold.red)
})

shards.on("death" , async (shard) => {
  shards.spawn(shards.totalShards , 10000);
  console.log(`[${new Date().toString().split(" ", 5).join(" ")}] Killed Shard #${shard.id}`.bold.red)
})



shards.spawn(shards.totalShards , 10000);

why there’s nothing in console

nimble mist
proud mortarBOT
nimble mist
tame iris

any idea what this is about

dense cape
bitter shadow
tame iris
bitter shadow
terse cairn
const express = require("express");
const app = express();

app.get('/', (req, res) => {
   res.send('Hello Express app!')
 });

app.listen(3000, () => {
   console.log('Bot started');
 });```

it will log err: `address already in use :::3000`
i think because shard 0 will use it then shard 1 will return the err

i did this but same err
```js
app.listen(3001 || 3002 || 3003, ()```
terse cairn

just listen on sharding manager or shard 0 only

terse cairn
terse cairn
half vessel
bitter shadow
bitter shadow

oh ok guess its just been an issue for me since a couple days weird

lost hatch

Some huge bot devs said, due to this issue they switched to other js libraries. But now we know the issue. The fix I implemented works but its not the best one. I need to push a better solution to that

lost hatch
bitter shadow
lost hatch
bitter shadow

I dont think I have the presence intent rn will just copy paste what you have currently in the pr. Thanks for helping me with that 👍

bitter shadow
arctic steeple

can i make a shard for every 5 server not every 2500 server ?

dense cape

You could if you wanted to, tho you may be restarting quite often depending on ur growth and may have some shards that have no guilds

nimble mist
frail marsh

Is sharding every 5 servers even useful YEP

dense cape

Nope

Easy way to waste cpu and consume login rate limits

vestal sluice
snow sierra

discord recommends you to start sharding at 2500

vestal sluice

yes but thats not what they were talking about

serene shell

Bot not spawning new shards automatically

In some servers it don't work

serene shell

That sucks cuz we r growing really fast rn

next plaza
serene shell

We grow like 500-600 Guilds per day

How would I make it so I have to restart it every week or so @next plaza

And I want to use your discord hybrid sharding thing for sharding.

next plaza
next plaza
undone cove

guys, is there a way to get in ready event the shard id ?

vestal sluice
undone cove

i don't asking this, i'm asking how to get the shard id with the client parameter in the ready event

vestal sluice
undone cove
vestal sluice

no, im using it, it works

undone cove

i want the shard id where the event is executed

vestal sluice

yes thats exectly what it does

example console output

undone cove

so the nb in "SHARD .." is client.shard.ids[0] ?..

vestal sluice

yes

undone cove

it seems strange to me but I will try

hollow quartz

How many guilds are on each shard? I thought its about 1000 but i have like 2200 now and its still 2 not 3 shard, when will the 3rd shard be created?

terse cairn

is there's anything i need to change in command handler after sharding?
because it duplicates messages on replit and if using VSC

client.on('interactionCreate', async interaction => {
  if (!interaction.isCommand()) return;
  const command = client.commands.get(interaction.commandName);
  if (!command) return;

  if (interaction.guild && interaction.channel.type == "GUILD_VOICE") return;
  try {
    await command.execute(interaction, client);
  } catch (error) {
    console.error(error);
    return interaction.reply({ content: 'ERR!!', ephemeral: true });
  }
});
vestal sluice
terse cairn

sometimes it send 3 times or 4 or 5

vestal sluice

that does look like duplicated processes to me

terse cairn

i just generated new token
same issue

vestal sluice

no lol
not like that

you are probably somewhere importing your client (requiring your bot file) which worked before sharding, but now youll have to import the manager and then use broadcastEval @terse cairn

terse cairn
vestal sluice

i dont know what you're doing, how am I supposed to know. the problem you described looks like you're running multiple instances of the client, you can achieve that by (for example) importing your client in a different file (const client = require("/bot.js").client, e.g.)

that would have worked before but with sharding, its creating another instance

you would need broadcastEval to do what you did before with the imported client

terse cairn

emoji_31


const { ShardingManager } = require('discord.js');

const manager = new ShardingManager('./bot.js', {
  // totalShards: 2,
  token: process.env.token
});

manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`));

manager.spawn({ timeout: -1 })
  .catch(console.error);

// module.exports = { manager }
``` this’s `index.js` 
and the Client and other things works fine in bot.js but it duplicate messages and almost everything.
Do i need to import manager?
@vestal sluice
vestal sluice

no, you dont understand me
the problem is not that file

vestal sluice

one of your bot files probably imports client

but since the bot.js file was never actually run, it runs it and creates a second instance of the client

terse cairn

4Fsurprized I’m dying

Duplicate messages

serene shell

My bot just doesn't work on some shards

It's weird with shards my bot just doesn't do anything on some servers

How to fix

snow sierra

it may require to resharding, which need to restart the bot

serene shell

As some of the servers aren't new and I have 8 shards so

And my bot is in 4k servers it just grew by 100

terse cairn
unborn ingot

Is it possible to use auto in the sharding Manager and only change it so that shard 0 recives only half the guilds? I want to do that because there will be some stuff only run on Shard 0 and it will have a bigger payload

dense cape

You can't control which guilds go to which shards, it’s determined by the sharding formula

Unless you become so popular that Discord has to distribute the guilds in a more equal manner

unborn ingot

I don't want to control what guilds go where, I just want to control how many goes where

sonic bear

you cant..... well you can change shard count that would increase or decrease guilds per shard

unborn ingot

Okay, the thing is that I just got an awnser to a question I didn't ask and My real question got ignored :) but still thanks to everybody who helps here

terse cairn
unborn ingot
unborn ingot

You should try resharding

hollow quartz

did already restart, didnt change anything

@unborn ingot

unborn ingot

Try Looking through the threads if you find something, if not maybe the search function reveals a solution to you

tender ibex

Hey, does someone know how to perform good clustering with discord.js bots?

unborn ingot

I think there was a extra nom package that did quite a good job and also allows it to be combined with internal sharding

terse cairn
serene shell

I have 8 shards and I'm in 4000 guilds so that should work right? But this happens in some servers pls help

tender ibex
clear patio
serene shell

And other stuff doesn't work in their server

Like pinging the bot to talk but the weird thing is that the bot is online in their server

unborn ingot
clear patio

try using catch() where you create the shards

clear patio
terse cairn

Can 1 user be in more than 1 shard?

fierce compass

yes

fathom relic

are there any other options for clustering besides kurasuta?

formal ivy

Hello, i am using discord.js 13 and have a question regarding sharding and database connections.

Currently i have 80 shards running, all using their own connection pool to a single mysql database. As i cache a lot of results, the database usage of every shard goes down after start. So at some point i have way more connections than needed, which takes a lot of ram on the database vps.

Now i would like to tunnel all db requests through the sharding manager's connection pool (is this a good idea?), but i can only find a broadcastEval function, where i can send messages to all shards. Is there a way to request-response (with async await) from one shard to the shardingManager only? How is this done?

winter garnet

Hey! How i can return structures such as Collections in a broadcastEval?

winter garnet
formal ivy
proud mortarBOT
nimble mist

And send your answer via Shard#message. Need to create a listener on both ends for the message event

winter garnet

client.shard.send()

nimble mist
winter garnet
nimble mist
formal ivy

can i await this client.shard.send() to respond with data from the shardingmanager, while still "being in" the handling of the interaction in the shard?

or will i have to, for instance, send the channelId of the user writing the command in the payload, and setup a new listener in the shard itself.

winter garnet
nimble mist What’s the use-case you want it for? Might be easier to provide fixes if I know ...

Yep! I have this Collection

  current: {
    track: 'test'
    title: 'test3',
    identifier: 'kh1sF-sbkbw',
    isStream: false,
    displayThumbnail: [Function: bound displayThumbnail],
    requester: GuildMember {
      guild: [Guild],
      joinedTimestamp: 1625738691136,
      premiumSinceTimestamp: null,
      nickname: null,
      pending: false,
      communicationDisabledUntilTimestamp: null,
      _roles: [Array],
      user: [User],
      avatar: null
    }
  },
  previous: null
]```
And i want to return it in a broadcastEval, so later i can update the queue in another shard after it gets reloaded

Like im savinf that Object and i want to keep it after i respawn a shard, so for that i want to save it

nimble mist
winter garnet

So what i do is a broadcastEval to the shard i am going to restart and i throws me back this Object

nimble mist
winter garnet
nimble mist

Ah, so you just want to save it so it can be reloaded after restart? Why not use database of any kind instead of trying to broadcastEval?

formal ivy
winter garnet

And if i save it in a database i need to update the database like every 5 seconds, imagine update a database on 100 shards every 5 seconds

nimble mist
formal ivy

The thing is, i am pretty confident that the amount of connections is the next limit i am facing. While this wont be a problem for a while still, it is the only thing that keeps me from simply firing up new databases, which would be nice, as the database is doing a lot of calculation for me. i can simply add databases from the logical perspective. but if i have lets say 1.000 shards, each connecting to 10 databases, thats 10.000 connections. wont this be a problem?

nimble mist
formal ivy
nimble mist

That’s what databases are made for. To have your data in one place accessible from many different places

formal ivy

Theres a reason why there is somethign called a sharded database... because a database also has its limits and bottlenecks

nimble mist

Yes, but if that was the case for you then how would introducing your ShardingManager as new bottleneck help with that in any way? You said that after some time you mostly do read operations on the database anyway, then replication would do the same trick without need of sharded DB

formal ivy

my bot is a statistics bot and the strain on the database is significant. the database does a lot of calculation. aside from the database. if all shards on one vps would share one connection, i could easily fire up new databases.

next plaza

At 80 Shards, you should cluster your bot. You will save a lot of ram and less connections to the db.

formal ivy

splitting the shards on multiple vps' wont reduce the number of connections, if every shard has its own connection

next plaza
formal ivy

is that "internal sharding"?

next plaza

Yeah, basically many processes internal sharded

formal ivy

by what factor can i reduce it that way? like 10 shards in one process? or more?

next plaza

Based on your load 8-16 Ws Shards

formal ivy

hmm that approach should work for a looooong time, but its depending on the amount of databases i add.

next plaza

Maybe switching to a other db such as pgsql, mariadb or even a nonsql ones

formal ivy

would those really make a difference?

i thought if i switch, it would be a document based, mongod, which comes with built in sharding possibilities. but the problem is with document based i would have to rethink all the calculations going on on the database level.

serene shell

I think I figured it out

If a user uses the settings command in a voice channel it breaks it for the shard

Nvm

nimble mist
terse cairn
serene shell

theres no errors must be an internal error

terse cairn
serene shell
terse cairn

we are talking about "interaction failed"

serene shell

its the new text channel vcs. the bug is u cant use buttons in them, it breaks the bot. stops the process

terse cairn
serene shell

its not an error with my code, it onyl happens in vc channels.

and it doesn't error in the terminal

even tho i used try and catch

terse cairn

i am talking about application commands, not vcs nor buttons

serene shell
terse cairn

whats ur djs version

serene shell
serene shell
terse cairn

voice text channels arent supported in it afaik

serene shell
terse cairn

wdym

serene shell

discord js version 13.3.1

terse cairn

remove and install it

serene shell
terse cairn

it says +

anyways it says those versions do not crash soo

nimble mist

It says they do not crash upon message receiving. They do crash on ButtonInteractions though

terse cairn

oh well ^

thats your issue then

nimble mist

Simply check if it’s a VC before creating buttons in it

And it won’t crash

buoyant anchor

hello! ive just made a very simple discord bot and i *think* i want to implement sharding. basically i want different servers to be like different instances and not share variables which i believe is where sharding should help. currently my variables are being shared across servers which im trying to get rid of. the below code is my index.js but my bot seems to keep sharing variables. can anyone help? :)

require('dotenv').config();

const { ShardingManager } = require('discord.js');

const manager = new ShardingManager('./src/bot2.js', { token: process.env.DISCORDJS_BOT_TOKEN });

manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`));

manager.spawn();```
thorn pine
buoyant anchor ```js require('dotenv').config(); const { ShardingManager } = require('discord....

You are misunderstanding the purpose of sharding. It is not necessarily to have different data across guilds, as that is extremely inconsistent and creates multiple issues due to bad code; the purpose of sharding is to split the bot's load onto multiple different threads in order to have better ping/responsiveness for all guilds. In addition, sharding is only recommended at around 2000 guilds anyway, so it might not be right for you to shard just yet.

If you want different data for guilds, I suggest storing the ids & data in a database or JSON file (may be unstable).

I can answer any other questions about sharding if you have any.

buoyant anchor
thorn pine
buoyant anchor Thanks for the clarification Dylan. Do you have any recommendations to get start...

It's fine staying in this channel:

To figure out which server a message is being sent on, considering you are using a messageCreate listener, you could use <message>.guild. (if you are listening interactions, that would be <interaction>.guild)

As for databases, it depends on how you are planning to use your bot. If you are using it for a single, smaller guild, I would suggest JSON files to store data (using fs read and write). Though, if you plan for your but to be in multiple servers with a good amount of data, I'd highly suggest MongoDB - its a very simple document based db, which is free for most use-cases.

buoyant anchor
thorn pine
buoyant anchor
thorn pine
buoyant anchor Sorry real quick before I stop bothering you 😅. is there anyway to list all the...

Absolutely no worries!

In order to get all the guilds the bot is in, you would use <client>.guilds.cache

To put that in a readable format, as that would be a massive list of all guilds with all their data, we can use "map".

Using <client>.guilds.cache.map(g => ...) we can display certain snippets of data about each guild, and it will be conjoined in a nice, clean message. For example we can use:

  <client>.guilds.cache.map(g => `${g.name} : ${g.id}`)

This displays a nice list of all guilds, but to make it even better, we can join each guild's data with a new line, using .join('\n')

All of this code together will create a nice list of all the guilds the bot is in:

// The Code:

<client>.guilds.cache.map(g => `${g.name} : ${g.id}`).join('\n')

// Possible Output:

`
ServerOne : 49288348023948
ServerTwo : 98209850293530
ServerThree : 78302855291530
`
buoyant anchor
thorn pine
waxen estuary

Does internal sharding (specifying shards: "auto" in ClientOptions) also only shows the users managed in the current shard when using UserManager.cache

nimble mist
proven iris

Why is there an error (zombie connection) and that the required number of guilds was not obtained within 15 seconds.. This happens when GUILD_PRESENCES intention is enabled, without it everything runs fine and the shards successfully connect to the gateway without any reconnection.

proven iris

🤠

terse cairn

Hey, I released my bot to production and after a while I get this error. I cant figure out what causes it.

is there a way to check where the error really originated?

fathom relic

are there any other options for clustering besides kurasuta?

nimble mist
crisp flicker

Why the shard gose down?

crisp flicker
sonic bear

Ye I've been getting the same close code 4009 (updating djs helped me)

nimble mist
nimble mist
crisp flicker
nimble mist
terse cairn

How check shard is online or offline

crisp flicker
nimble mist
nimble mist
terse cairn
nimble mist
terse cairn
nimble mist
nimble mist
terse cairn Yes

Then use fetchClientValues('ws.status') and you even get an array of all shards and if they are online

Well, you might get no result if it’s offline, but that’s as good as false to know it’s not online

crisp flicker
nimble mist
crisp flicker
bitter shadow

this maybe it idk

@crisp flicker not 100% sure tho if that solves ur issue

true talon

Why my bot replies twice when i shard my bot? My bot is in 70 servers, ik its less but all my friends do it at 30-50 servers. They get it to work, but when i shard my bot replies twice :(

true talon

wait

const { ShardingManager } = require("discord.js"); const logger = require(`${process.cwd()}/modules/logger.js`); foxieShardingManager = class extends ShardingManager { //shardingManager }; 
const shardingManager = new foxieShardingManager(`${process.cwd()}/index.js`, { totalShards: 5, respawn: true, mode: "process", token: process.env.DISCORD_TOKEN, execArgv: ["--trace-deprecation", "--trace-warnings"] }); shardingManager.on("shardCreate", (shard) => console.log(`Shard ${shard.id} Initiated...`)); try { shardingManager.spawn({timeout: -1}); } catch(e) { console.log("Sharding Manager Error", e) } logger.color("yellow").log("-".repeat(15), "SHARDINGMANAGER LOADED", "-".repeat(15));
true talon
terse cairn
crisp flicker
terse cairn

if i'm using a command in a guild that in shard 1
and i want the bot to reply with the server name of a server in shard 2
how to do it A_thinking

crisp flicker

or channel

terse cairn
crisp flicker
terse cairn
snow sierra

because its throw rejection. also why do you need to fetch them? its will stay available after ready state.

terse cairn
snow sierra
snow sierra

elaborate

terse cairn

I want to get a server name that might be in other shard and send it in the same channel that i used the command in
it worked with fetch

snow sierra

why dont use broadcastEval? or if you using fetch you have to catch the rejection if its does not exist

terse cairn
charred arch

reject(new Error('SHARDING_READY_TIMEOUT', this.id));
^
Error [SHARDING_READY_TIMEOUT]: Shard 0's Client took too long to become ready.
at Timeout.onTimeout (/home/container/node_modules/discord.js/src/sharding/Shard.js:163:16)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
[Symbol(code)]: 'SHARDING_READY_TIMEOUT'

nimble mist
terse cairn

Hey, what does this error mean? what error message key?

and how would I fix this?

nimble mist
terse cairn Hey, what does this error mean? what error message key?

Looks like you have a recursive call on a shard messaging function. Either broadcastEval or send directly judging by the line numbers it might be fetchClientValues. Do you try to fetchClientValues('shard') or something along those lines? Or do you listen on the 'message' event in ShardingManager and send something back there that calls a function that will fetchClientValues again?

terse cairn

hey sorry to bother ya but can you please send me that lib ?

terse cairn
nimble mist
terse cairn

yes thats all right, it serializes

I need to get guildID property from each instance and how many instances there is

when it converts to json its an object with the guildID property and its an array so I can get the length

nimble mist
hollow quartz

How many guilds are on each shard? I thought its about 1000 but i have like 2200 now and its still 2 not 3 shard, when will the 3rd shard be created?
asked this a while ago and didnt receive a proper answer, so im asking again, now with almost 2300 servers and still 2 shards. i did restart

fierce compass

its about 1000 if you dont set the shard count manually

hollow quartz
fierce compass

show the options you're using on the shardingmanager

hollow quartz
fierce compass

and you restarted that file?

hollow quartz
fierce compass

make a GET /gateway/bot request to the discord api using your bots token on the authorization header and show the result

curl example: curl -H "Authorization: Bot YOUR_BOTS_TOKEN" https://discord.com/api/v9/gateway/bot

hollow quartz
fierce compass

ok, discord suggest that your bot uses 2 shards, thats why the shardingmanager is only creating 2 shards

hollow quartz

but why? i thought its 1000 per shard

fierce compass

¯_(ツ)_/¯

humble tangle
[WS => Shard 20] Heartbeat acknowledged, latency of 121ms.
[WS => Shard 0] [CLOSE]
    Event Code: 1000
    Clean     : false
    Reason    : 
[WS => Shard 0] Clearing the heartbeat interval.
[WS => Shard 0] WS State: CLOSED
[WS => Shard 26] Heartbeat acknowledged, latency of 202ms.
[WS => Shard 28] [CLOSE]
    Event Code: 1000
    Clean     : false
    Reason    : 
[WS => Shard 28] Clearing the heartbeat interval.
[WS => Shard 28] WS State: CLOSED
[WS => Shard 30] [CLOSE]
    Event Code: 1000
    Clean     : false
    Reason    : 
[WS => Shard 30] Clearing the heartbeat interval.
[WS => Shard 30] WS State: CLOSED
[WS => Shard 18] [CLOSE]
    Event Code: 1000
    Clean     : false
    Reason    : 
[WS => Shard 22] Clearing the heartbeat interval.
[WS => Shard 22] WS State: CLOSED
[WS => Shard 17] [CONNECTED] Took 359ms
[WS => Shard 17] Clearing the HELLO timeout.
[WS => Shard 17] Setting a heartbeat interval for 41250ms.
[WS => Shard 17] [RESUME] Session f7296839c553980131d684ff0bdde3a5, sequence 1446
[WS => Shard 17] Tried to send packet '{"op":6,"d":{"token":"NzXndXIUssnXij36A3OTgxODQ2AjPx.X_bEg.51QMzR2OF41NARLksUYYd6G4GpyoWk","session_id":"f7296839c553986784340131d684ff0bdde3a5","seq":1425}}' but no WebSocket is available!
[WS => Shard 17] [DESTROY]
    Close Code    : 4000
    Reset         : false
    Emit DESTROYED: true
[WS => Shard 17] Clearing the heartbeat interval.
[WS => Shard 17] Shard was destroyed but no WebSocket connection was present! Reconnecting...

My bot is online but not responding to commands and I get these weird messages in client.on('debug') event.

fierce compass

that message contains your bots token, might want to reset it

hollow quartz

lmao

humble tangle

but tell me what's the error

[WS => Shard 20] Heartbeat acknowledged, latency of 121ms.
[WS => Shard 0] [CLOSE]
    Event Code: 1000
    Clean     : false
    Reason    : 
[WS => Shard 0] Clearing the heartbeat interval.
[WS => Shard 0] WS State: CLOSED
[WS => Shard 26] Heartbeat acknowledged, latency of 202ms.
[WS => Shard 28] [CLOSE]
    Event Code: 1000
    Clean     : false
    Reason    : 
[WS => Shard 28] Clearing the heartbeat interval.
[WS => Shard 28] WS State: CLOSED
[WS => Shard 30] [CLOSE]
    Event Code: 1000
    Clean     : false
    Reason    : 
[WS => Shard 30] Clearing the heartbeat interval.
[WS => Shard 30] WS State: CLOSED
[WS => Shard 18] [CLOSE]
    Event Code: 1000
    Clean     : false
    Reason    : 
[WS => Shard 22] Clearing the heartbeat interval.
[WS => Shard 22] WS State: CLOSED
[WS => Shard 17] [CONNECTED] Took 359ms
[WS => Shard 17] Clearing the HELLO timeout.
[WS => Shard 17] Setting a heartbeat interval for 41250ms.
[WS => Shard 17] [RESUME] Session f7296839c553980131d684ff0bdde3a5, sequence 1446
[WS => Shard 17] Tried to send packet '{"op":6,"d":{"token":"NzXndXIUssnXij36A3OTgxODQ2AjPx.X_bEg.51QMzR2OF41NARLksUYYd6G4GpyoWk","session_id":"f7296839c553986784340131d684ff0bdde3a5","seq":1425}}' but no WebSocket is available!
[WS => Shard 17] [DESTROY]
    Close Code    : 4000
    Reset         : false
    Emit DESTROYED: true
[WS => Shard 17] Clearing the heartbeat interval.
[WS => Shard 17] Shard was destroyed but no WebSocket connection was present! Reconnecting...

My bot is online but not responding to commands and I get these weird messages in client.on('debug') event. Token is already reset stop reminding me.

hollow quartz

dont just spam it please

snow sierra

is that token has been invalidated?

vestal sluice
merry bay

I'm getting something similar after pushing an update to my bot and restarting.
Token was fine (and I've reset it just incase) but shards are now starting then dying with an error stating that it failed to connect to gateway followed by session being invalid

[WS => Shard 1] Setting a HELLO timeout for 20s. [WS => Shard 1] [CONNECTED] Took 137ms [WS => Shard 1] Clearing the HELLO timeout. [WS => Shard 1] Setting a heartbeat interval for 41250ms. [WS => Shard 1] [IDENTIFY] Shard 1/75 with intents: 5009 [WS => Shard 2] [READY] Session 571e8008b0f1c08b43d0054cff39c286. [WS => Shard 2] [ReadyHeartbeat] Sending a heartbeat. [WS => Shard 2] Heartbeat acknowledged, latency of 303ms. [WS => Shard 1] [INVALID SESSION] Resumable: false. Shard ID:1 - Reconnecting [WS => Shard 1] Failed to connect to the gateway, requeueing... [WS => Manager] Shard Queue Size: 1; continuing in 5 seconds... [WS => Shard 2] Shard received all its guilds. Marking as fully ready. Shard ID:2 - Online Shard ID:2 - 0 unavaialable guilds Shard ID:3 - Launched Shard ID:2 - logged in Shard ID:3 - DB Connector Loaded Shard ID:3 - Started refreshing application (/) commands. Provided token: NDA5ODIyODMyMjU2ODc2NTQ1.Wnd7QQ.*************************** Preparing to connect to the gateway... [WS => Manager] Fetched Gateway Information URL: wss://gateway.discord.gg Recommended Shards: 53 [WS => Manager] Session Limit Information Total: 1000 Remaining: 878 [WS => Manager] Spawning shards: 3 [WS => Shard 3] [CONNECT] Gateway : wss://gateway.discord.gg/ Version : 9 Encoding : json Compression: none

merry bay

This appeared to be an issue with unavailable guilds.
Adding waitGuildTimeout:1000 in front of my intents appears to of fixed the issue

nimble mist

@terse cairn ask here

terse cairn
nimble mist

There are two options, internal or traditional sharding

nimble mist

internal is easier, traditional is needed once your bots gets too big

terse cairn

@nimble mist how to use internal one?

nimble mist

internal sharding is done automatically by djs as soon as you specify shards: 'auto' in your ClientOptions (or a number higher than 1)

nimble mist
terse cairn
terse cairn

@nimble mist like that?

nimble mist
terse cairn
nimble mist
terse cairn

@nimble mist I have created this

nimble mist
terse cairn

Yeah so what now?

@nimble mist now how to show shard count in stats command?

proud mortarBOT
nimble mist

client.shard is a ShardClientUtil

terse cairn

@nimble mist discord.js 12v is good for 2022?

terse cairn
nimble mist

djs v12 isn’t good for a long time now

dense relic

Quick question as I'm looking into sharding my bot soon

I understand I can shard manually by creating individual instances and providing certain client options, but I'm a little confused from looking the clientoptions docs

shardCount should be the total number of shards right? So imagine I have 10 shards in total, that should be 10?
Where does the ID of that current shard go? What parameter is that? Is it shards?
https://discord.js.org/#/docs/discord.js/stable/typedef/ClientOptions

So my first shard would be
shardCount: 10
shards: 0

And then the 3rd shard would be
shardCount: 10
shards: 2

And the final 10th shard would be
shardCount: 10
shards: 9

Right?

peak oar
/home/newbot/node_modules/discord.js/src/sharding/ShardClientUtil.js:35
        process.send({ _ready: true });
                ^

TypeError: process.send is not a function
    at Client.<anonymous> (/home/newbot/node_modules/discord.js/src/sharding/ShardClientUtil.js:35:17)
    at Client.emit (node:events:539:35)
    at WebSocketManager.triggerClientReady (/home/newbot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:384:17)
    at WebSocketManager.checkShardsReady (/home/newbot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:367:10)
    at WebSocketShard.<anonymous> (/home/newbot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:189:14)
    at WebSocketShard.emit (node:events:527:28)
    at WebSocketShard.checkReady (/home/newbot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:475:12)
    at WebSocketShard.onPacket (/home/newbot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:447:16)
    at WebSocketShard.onMessage (/home/newbot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
    at WebSocket.onMessage (/home/newbot/node_modules/ws/lib/event-target.js:199:18)
import { ShardingManager } from 'discord.js';
import config from "./utils/config";
import logger from './utils/logger';

const manager = new ShardingManager('./index.js', { token: config.token });

manager.on('shardCreate', shard => logger.manager.info(`Launched shard ${shard.id}`));

manager.spawn();

import './consolecommands';
serene shell

Help I need to always restart my discord bot and why

It stops working on certain shards

serene shell

How to detect a shard crash? I don't know why some shards stop working

After like 1 day

bitter shadow

@serene shell this may be your issue not 100% sure tho

serene shell

How do I fix this?

serene shell
bitter shadow
bitter shadow

you do have the debug event on tho right?

serene shell

If that was the issue how would I fix

bitter shadow

What I did is just install d.js using that pr or wait until they merge it and fix in v13.7

might not be the best idea tho because v13.7 is not out yet and it would install the progress on that as well

best thing would be to find out first if thats really the issue you have and listen to the debug event for example and see if a shard disconnects bc of zombie connection

astral remnant

How come same guild are in two shards

Both are same guild

hybrid iron
astral remnant
hybrid iron
astral remnant
hybrid iron
astral remnant

No I didn't and fetching has nothing to do with this

hybrid iron
astral remnant
hybrid iron
astral remnant

ohk thnx

lunar rapids

when is it good to get shards on the bot?

half vessel
lost hatch
snow sierra
serene shell
snow sierra

yup

serene shell
snow sierra yup

great people think its my fault that my bot doesnt work on some shards

nimble mist
nimble mist

Question has been answered (in a way)

nimble mist
serene shell

cuz my shards keep on crashing and I dont know why and I think it might be this. they jsut stop working ranodmly

nimble mist
serene shell

So what do I do k
now gh pr checkout 7581

nimble mist

You‘d need to have GitHub client installed for that

lost hatch

@serene shell just copy paste those 2 files from pr on v13 module of djs on ur machine

lost hatch

idk what to answer your "how" ive just told you what to do using the pr

serene shell

download which files

lost hatch

just copy the files from that pr and paste it in ur node_modules/discord.js/

serene shell

which fiels

lost hatch
serene shell

where do i download

exotic sapphireBOT
astral remnant
serene shell

and i cant just straight up copy cuz of this

snow sierra

just install it, npm i legendhimslef/discord.js#v13

cobalt ore
serene shell
snow sierra

it just install other user pr. not main repo

afaik you still cant use vc text update, they just patch bot crash rn (dont know if its merged yet)

astral remnant

Why guilds.fetch makes a cache in wrong shard, can't it create the cache in the shard in which guild is present. Like if I use guilds.fetch in Shard ID: 2 and the guild is in Shard ID: 0 another cache is created in Shard ID: 2 and that increases the number of unavailable guilds

hybrid iron
astral remnant

I did that and it got in all shards

hybrid iron
proud mortarBOT

method GuildManager#fetch()
Obtains one or multiple guilds from Discord, or the guild cache if it's already available.

faint monolith

is it possible to launch different shards on cloudflare workers or similar?

nimble mist
faint monolith
nimble mist
faint monolith
remote frigate

can the ShardingManager create clusters across cpu cores?

nimble mist
terse cairn

is it possible to shard across multiple machines?

^please ping me

terse cairn
module.exports = new Discord.Client({
    shards: [0, 1]
    // ..
});

like this?

ex. totalshards is 4, so first machine will have shardList: [0,1] and second will have shardList: [2,3]

terse cairn

where do i have to define shardlist tho? ShardingManager options or?

yeah

oh, i don't get that in vsc

shards have to run in order right?

wdym?

nvm, i got another question

let's say we have got machine1 and machine2

can machine1 use shardList: [0, 2, 4] and machine2 use shardList: [1, 3, 5]

sure ig

nimble mist

totalShards In ShardingManager

terse cairn
terse cairn

oh, i see, alright, thank you

tired briar

is there a way to pass args to the bot.js that are defined in the shard manager

proud mortarBOT
terse cairn

How can I get the name, icon... of a channel that might be in other shard and send it in the same channel that i used the command in

hybrid iron
terse cairn

try {
let channel = await client.channels.fetch("847901485740457994");
  if(channel) {
    console.log(channel)
//...``` no err nothing  @hybrid iron
terse cairn
 TypeError: Discord.MessageEmbed is not a constructo

 client.shard.broadcastEval(async (c, { Discord }) => {
          const channel = c.channels.cache.get("807703389294166087");
          if (channel) {
            let embed = new Discord.MessageEmbed()
// ...
 }

        }, { context: { Discord: Discord } })```
fierce compass

read the latest pinned message

despite being outdated, the concept is still true (it applies to the context as well)

terse cairn

A_thinking

terse cairn
let channel = client.channels.cache.get(ID);
if (channel) {
  let user = await client.users.fetch(vote.user);
  user.send("HI").then(()=>channel.send(`sent to ${user}`)
}
``` is this will work?
if channel's shard is not the same as user's shard, is there a good way to do it
nimble mist
nimble mist

client.shard.fetchClientValues("ws.status") for example

nimble mist

Yes, because it’s a Promise. Like all fetch methods are

Resolve the promise

proud mortarBOT
nimble mist

But honestly: how can you run a sharded bot but not know about Promises?

I‘m more asking how it comes that your bot is so big that it needs sharding yet you don’t know JS fundamentals that are used in about 80% of d.js code

pale sapphire

The bot can grow really quick and he really has a good bot idea and didn't get time to fully learn JS and now he needs sharding. (Although, it's rare that happens.)

nimble mist

The messages I responded to were deleted, so I look like I‘ve been talking to myself a lot🤦‍♂️

terse cairn

how can I pass node arg to the shard?

my bot is crashing due to low heap I want to add --max_old_space_size=4096

fierce compass

use the execArgv option on the ShardingManager

terse cairn

and what is shardargs?

terse cairn

also debug event is not firing. Im trying to debug this but its not firing

switching to execArgv='--max_old_space_size=4096' my bot wont launch
I get the timeout as shows in the screenshot above 😦

actually whenever I set my execArgv, hwne starting the bot it enters nodejs

okay never mind. docs are wrong..type is string array not string

warped idol

Hi everyone, I have a question. The docs / guides for creating commands shows a script called 'deploy-commands.js'. however, this script assumes your bot isn't sharded.

My question: I am using the ShardingManager Kurasuta, how am I expected to deploy commands to a sharded bot? Do I take the bot offline and online? Or can the ShardingManager manager find every guild for me so that I can deploy the commands by GuildId as shown below:

const { SlashCommandBuilder } = require('@discordjs/builders'); 
const { REST } = require('@discordjs/rest'); const { Routes } = require('discord-api-types/v9');
const { clientId, guildId, token } = require('./config.json');

const commands = [ 	new SlashCommandBuilder().setName('ping').setDescription('Replies with pong!'), 	new SlashCommandBuilder().setName('server').setDescription('Replies with server info!'), 	new SlashCommandBuilder().setName('user').setDescription('Replies with user info!'), ] 	.map(command => command.toJSON());

const rest = new REST({ version: '9' }).setToken(token);
 rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands }) 	.then(() => console.log('Successfully registered application commands.')) 	.catch(console.error);

As you can see the example script assumes you know the guildId, I need to find a way of using the kurasuta ShardingManager to collect every guildId so that I can deploy my commands without taking the bot offline

terse cairn

this is djs help, not kurasuta

warped idol

Kurasuta is just a thin layer over ShardingManager

Ok just ignore Kurasuta then, how would I go about this if it was ShardingManager?

meager haven
warped idol

Yeah thank you the optimization is nice but my issue is that I need to understand how you get every guildId from a sharded bot using ShardingManager

meager haven

until I realized what you meant

warped idol

The code i posted was just what i found on the discord.js guide on deploying commands

nimble mist
warped idol

ooh I see

that makes sense so, I got confused how the documentation suggested deploying by guild, Routes.applicationGuildCommands(clientId, guildId)

nimble mist
warped idol
proud mortarBOT

Suggestion for @warped idol:
guide Interactions: Registering slash commands - Global commands
read more

warped idol

thank you ❤️

this completely solves my problem, much appreciated

devout vine

Shards should be auto-respawning when they die right? I have situations where like 1 shard randomly dies, the bot shows offline for people in those shards and my fetchClientValue calls don't return. I have to restart the whole bot to get it to work again.

I'm adding some additional logging to see what's going on but have to wait for it to happen again.

alpine stirrup

Shard 0's Client took to long to become ready. at Timeout.setTimeout [as _onTimeout] (/node_modules/discord.js/src/sharding/Shard.js:89:31) at ontimeout (timers.js:498:11) at tryOnTimeout (timers.js:323:5) at Timer.listOnTimeout (timers.js:290:5)

Why I sometimes receive this error and how can I fix 🥲

nimble mist
exotic sapphireBOT
alpine stirrup

oh tks

nimble mist
tribal meteor

hey how can i fix this err?

nimble mist
tribal meteor
nimble mist
hasty stag

by the way dont shard on replit

nimble mist

Don’t host anything you want to have taken serious on repl.it would be my suggestion

alpine stirrup
alpine stirrup
nimble mist
alpine stirrup
nimble mist

That’s not gonna work with a sharded bot. Get a real hoster

alpine stirrup

*cause it the last one allow me to host free with

nimble mist

Well, if your bot is so big it needs sharding you won’t be able to get it hosted for free anywhere

alpine stirrup

Oh, thanks for suggestions

terse cairn
client.on('ready', async () => {
  try {
    let qu = await vC.find({});
    const player = createAudioPlayer();
    let resource = createAudioResource(something);
    ////////////////////
    for (let i in qu) {
      let roomid = qu[i].roomID;
      let room = client.channels.cache.get(roomid);
      // if (!room) continue;
      if (room) {
        let connection = joinVoiceChannel({
          channelId: room.id,
          guildId: room.guild.id,
          adapterCreator: room.guild.voiceAdapterCreator,
        });
        connection.subscribe(player);
        player.play(resource);
      }
    }
    player.play(resource);

    player.on(AudioPlayerStatus.Idle, async () => {
      let resource = createAudioResource(...);
      player.play(resource);
    });
  } catch (er) {
    console.log("catchQur24Er " + er)
  }

});```
How can i put everyting inside `if(room) {here}`
Or is it ok to keep it like this while Sharding?
nimble mist
terse cairn

A_thinking

terse cairn
nimble mist
terse cairn

But there are things i want them out the for loop like
Player.play()
Because i don’t want many player, I want only 1 player

nimble mist

Well, you will have to have 1 player per shard anyway 🤷‍♂️

terse cairn

    player.on(AudioPlayerStatus.Idle, async () => {
      let resource = createAudioResource(...);
      player.play(resource);
    });

What about this, do i need to check for room

nimble mist

No, because the player will only be subscribed to on the channels that exist in that shard anyway

empty mountain

Why does discord api block my ip after all of my shards have been spawned?
like it works before the last one is spawned and then it gets blocked

nimble mist
empty mountain

I don't think its logging too fast

nimble mist

Where do you host your bot?

empty mountain

hetzner

it started after i switched to v13

nimble mist

So dedicated IP?

empty mountain

but the spawn delay doesn't even do anything it still spawns right after the next is ready

yes dedicated

nimble mist
empty mountain

doesn't matter how much i set it still always spawns right after

nimble mist

Doesn’t answer my question what you tried but okay

empty mountain

ye i have tried 10 second delay to 1 minute delay and still

but this started to happen after i switched to v13

empty mountain

??

nimble mist

My guess would be there’s some oversight where you didn’t fully update your code to v13 somehow but that’s full speculation without any code

empty mountain
const { ShardingManager } = require('discord.js');
const manager = new ShardingManager('./main.js', { token: settings.token, totalShards: 'auto', delay: 15000 });

manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`));

manager.spawn();
nimble mist
empty mountain

welp, but that still doesn't explain why it breaks now right after i have updated to v13

nimble mist

Probably because you had something in v12 that slowed the becoming ready which isn’t there anymore in v13 (could be due to less caching and fetching at the start for example)

empty mountain

Ye maybe. I tried now with the delay, thanks

next plaza
knotty widget

Just curious, is there a list of status codes for client.ws.status? Seems 0 is online, and 3 is offline or waiting, but I can't seem to find an actual key or list of what each means

nimble mist
terse cairn

no? the delay spawns despite shards being ready or not

nimble mist
terse cairn no? the delay spawns despite shards being ready or not

 for (const shardId of this.shardList) {
      const promises = [];
      const shard = this.createShard(shardId);
      promises.push(shard.spawn(timeout));
      if (delay > 0 && this.shards.size !== this.shardList.length) promises.push(sleep(delay));
      await Promise.all(promises); // eslint-disable-line no-await-in-loop
    }

The next shard only gets spawned once the spawn and the delay promise resolve

terse cairn
nimble mist
terse cairn

now you've just argued with urself

actually

createShard doesnt wait for the shard to become ready iirc

it just creates a child process or a worker

nimble mist
nimble mist
serene shell

Help why do my shards keep on doing this

snow sierra

do u use zombie connection fix pr?

serene shell

So it's 100% that?

snow sierra

why you still dont try to use

serene shell
snow sierra

npm i legendhimslef/discord.js#v13

serene shell
snow sierra

why dont try and see?

serene shell
snow sierra

bruh

serene shell
snow sierra bruh

As Jen is here for the phones so if I do it now and it breaks my Bot then I have to wait till I'm home

snow sierra

just try, if it broke just switch to stable ver. i dont know if its already have tiv fix or not. im not gonna see all commit tho

serene shell

I need to use v13 beta or dev or whatver u call iit

snow sierra

are you on v13 or v14

serene shell

i cant be on v13 stable

so im techically on 13.7.0 beta

snow sierra

that pr based on v13 beta

serene shell
snow sierra
serene shell

ok cant rn cuz as I said jen came for the phones xd

serene shell

npm i legendhimslef/discord.js#v13
And I'm running this

serene shell
serene shell

I used npm i legendhimslef/discord.js#v13 but it errored

nimble mist
serene shell
serene shell
serene shell

hopefully my shards dont go randomly offline now.

snow sierra
storm sage
lost hatch
nimble mist
storm sage I'm curious to know how discord generates worker and process id https://discord....

The same way you can cluster your shards. Each server is assigned a starting point from which on they numerate their processes. Discord defines an upper limit of processes per server and makes sure the range is big enough to fit them all🤷‍♂️ workers don’t need to be handled separately, as each process is only on one server, so workerIDs only need to be unique in each process

proven bear

What things can cause the Sharding are still being spawned? (mention pls)

terse cairn

i'll do this for example to send a message

let data = "cId";
let channel = client.channels.cache.get(data);
if (channel){
  channel.send("G");
  // ..
}

but if then I deleted the channel while the bot offline
how can i know the channel is not on any shard, deleted, not available

nimble mist
zinc plank

is there any option for running specific file on a group of shard
like i want a index.js running on shard #1
and index2.js running on shard #2

terse cairn
serene shell
nimble mist
terse cairn
terse cairn

if it’s available in the cache, then it’s fine i think. I don’t care if it will fetch or cache, what i want to catch if it can’t reach that room for any reason

Or I’m wrong?

lost hatch
serene shell
sonic bear

It's an event

<Client>.on("debug", function(info){ console.log(debug -> ${info})});

nimble mist
terse cairn
 let all = await hsnM.find({});
      for (let i in all) {
        if (all[i].roomID) {
          let data = all[i].roomID;
          let time = all[i].time;
          let sId = all[i].serverID;
          // let room = client.channels.cache.get(data);

          if (Date.now() > time) {    
            let room;
            try {
              room = await client.channels.fetch(data);
            } catch (er) {
              hsnM.findOneAndRemove({ serverID: data }, (error, del) => {
                if (error) { console.log(error) }
                else {
                  console.log(`❌ HHSSNN del ${sId}`)
                }
              })
// ...
            }```
I'm doing like this, and the channel is deleted

it will log many times, but the channel will not be really removed from DB
@nimble mist

terse cairn
terse cairn
terse cairn
terse cairn
terse cairn

djs is literally a wrapper and mongoose is literally a package to handle mongoose operations

amber pewter

Hi I can't connect my account GIthub To heroku this is my error

snow sierra

this is not heroku support

nimble mist
amber pewter

Oh ok i'm gonna see

edgy lake

Does shardCreate get emitted for a shard that's been resurrected (ie died and then recreated)?

nimble mist
proud mortarBOT
edgy lake

I see

nimble mist

No, not that one. The event with the same name

edgy lake

Yeah I found it. Thanks!

long night

Hey! New to sharding. This might be a broad question but what are some things that could cause a shard to take too long to become ready?

nimble mist
long night

yeah definitely not using repl.it. know better than that lol. I'll look into the other one, thanks!

abstract elm

Alrighty, recently moving to v13 after a rewrite from v12 commando, we've had some issues into sharding (23k guild bot, ~23 shards). When it comes to sharding, they spawn extremely slowly, and sometimes time's out (around shard 2). Code for spawning shards is as stated, manager.spawn(manager.totalShards, 5500, -1)

terse cairn

so for you it will be manager.spawn({ timeout: -1 })
(i ommited other options because they are the same as the default ones)

terse cairn

can i internal shard forever?

nimble mist
nimble mist
dense cape

Also keep in mind that internal sharding doesn't make full use of cpus, it runs on a single process

charred arch
/home/container/node_modules/discord.js/src/sharding/Shard.js:163
        reject(new Error('SHARDING_READY_TIMEOUT', this.id));
               ^
Error [SHARDING_READY_TIMEOUT]: Shard 2's Client took too long to become ready.
    at Timeout.onTimeout (/home/container/node_modules/discord.js/src/sharding/Shard.js:163:16)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7)
Emitted 'error' event on Shard instance at:
    at /home/container/node_modules/discord.js/src/sharding/Shard.js:392:49 {
  [Symbol(code)]: 'SHARDING_READY_TIMEOUT'
}
charred arch
serene shell
covert silo

Hi I have a question, I will soon start sharding my bot. It sends a message in a specific channel on my server when a user gets a rare item. Will that channel still be seen by all shards with this :

client.channels.cache.get(`821762092943961098`).send({ embeds: [itemEmbed] })

If not, how do I get this channel?

nimble mist
covert silo
covert silo

Ok thanks :D

proud mortarBOT
stiff gull
proud mortarBOT

Suggestion for @covert silo:
guide Popular Topics: Webhooks
read more

forest shuttle

Why would a discord client have more than one shard? client.shard.ids returns an array. Could it have multiple id's?

dense cape

could it have multiple ids
Yes, one per shard

forest shuttle
dense cape

Yes, by default

forest shuttle

Perfect, thanks 🙂

vestal sluice

How can I stop my shard from restarting whenever a command was used before its ready? it immediately throws unknown interaction and has to restart then

nimble mist
vestal sluice

if (!client.isReady()) return; as the first line in my event, still get unknown interaction as soon as its ready

nimble mist
vestal sluice `if (!client.isReady()) return;` as the first line in my event, still get unknow...

That sounds like you get queued interactions somewhere 🤔 very weird… one thing you could (and should) do is wrap your code in a try catch (or directly chain a catch to your command calling if applicable) provided you await all interaction acknowledging methods everywhere. Else you could make a process.on('unhandledRejection' handler (but log all rejections you ignore that way to make sure you don’t get more serious errors)

vestal sluice
module.exports = {
    name: 'interactionCreate',
    async execute(int, client) {
        try {
          // ...
        } catch (error) {
            const ignoreErrors = [10062];
            if (!ignoreErrors.includes(error.code)) console.error(error);
        }
    }
}
nimble mist
vestal sluice

hmm thought i did

ill recheck, thanks

molten cape

Hi im a bit concerned about this

it never used to restart like this

nimble mist
molten cape

it destroys all connected players

it started happening yesterday

nimble mist

Do you have lots of DMChannel open?

molten cape
molten cape
covert silo
dusty gate

will djs v14 support clusters?

terse cairn
vestal sluice still doesnt work

This works with me, it’ll throw an err but won’t restart


process.on('unhandledRejection', (err) => {
  console.error(`UNhandledRejection ` + err);
}); ```
nimble mist
merry ocean

how to shard?

proud mortarBOT

Suggestion for @merry ocean:
guide Sharding: How does sharding work?
read more

merry ocean

thx

merry ocean
nimble mist
merry ocean

to against errors

my bot eval is public

nimble mist
merry ocean
nimble mist
merry ocean

sharding wont work - I made the bot login after create shards. Why it still exit before the bot read

nimble mist
merry ocean
small sable

did you fix this? if yes, then how? i am facing this in internal sharding

dreamy forge

Sorry homie

small sable
dreamy forge

Lemme just search through some old messages and see if I can find it

@small sable that issue was on an old version though, would be easier to just upgrade to stable

small sable
dreamy forge

it was on v12.5.1 for me

Still running on that version now sip

Alright found it;

this happens when the socket disconnects before the open event is fired; for me the fix was to simply add another check in /src/client/websocket/WebSocketShard.js at around like 270, something like if(!this.connection) return

Although if you are on latest, then I guess they didn't fix it yet, since it was a known issue on v12

If you dig a bit deeper, you'll see that the error causing the issues is

/chip/node_modules/discord.js/src/client/websocket/WebSocketShard.js:270
    this.debug(`[CONNECTED] ${this.connection.url} in ${Date.now() - this.connectedAt}ms`);
                                              ^

TypeError: Cannot read property 'url' of null
    at WebSocketShard.onOpen (/chip/node_modules/discord.js/src/client/websocket/WebSocketShard.js:270:47)
    at WebSocket.onOpen (/chip/node_modules/ws/lib/event-target.js:144:16)
    at WebSocket.emit (node:events:329:20)
    at WebSocket.setSocket (/chip/node_modules/ws/lib/websocket.js:177:10)
    at ClientRequest.<anonymous> (/chip/node_modules/ws/lib/websocket.js:670:15)
    at ClientRequest.emit (node:events:329:20)
    at TLSSocket.socketOnData (node:_http_client:556:11)
    at TLSSocket.emit (node:events:329:20)
    at addChunk (node:internal/streams/readable:304:12)
    at readableAddChunk (node:internal/streams/readable:279:9)
    at TLSSocket.Readable.push (node:internal/streams/readable:218:10)
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:192:23)
dreamy forge

I can't guarantee this works on whatever version you're on though

lost hatch
dreamy forge

I added the check at onOpen, this event is kinda useless anyway since it only sets a status

But this is only tested to work in v12.5.1, unless they didn't change anything here it shouldn't work in other versions

If there is no this.connection, then the socket events are already useless, what I did would simply avoid the error coming up, but its not really a fix for anything

This issue has been known for a long time, if it still exists on current stable then 💀

nimble mist
dusty gate how so

By providing a list of shards that the ShardingManager should spawn in its options. Along with the amount of totalShards that exist

proud mortarBOT
lost pecan

not sure if this is actually a question about sharding, but I was wondering if there is a standard way to handle updates without downtime (even though I have a single bot instance still)
basically, I have a setup where I'm autodeploying my bot, but currently there is short downtime during the deployment where the existing instance is terminated but the new one hasn't come online yet

I'd like to start the new instance first, then once its online terminate the old one. the obvious problem being that now there is a small window where two bots might handle a command. is there a straightforward way to ensure only one of my instances gets any particular command?

devout vine

Discord.js attempts to avoid rate limits by queuing up API calls correct? I am running into issues hitting the global rate limit and I think it's partially due to running shards on multiple different machines, each with their own separate API queues. Discordeno solves this by have a single REST handler for all shards to use. Does discord.js have plans to add anything like this? Or do any 3rd party packages exist to handle this?

dense cape

In the future, you should be able to easily change out any module with a custom implementation or extension

winter garnet

Hey! Anyone know if there's a way to in the same shardingManager create a shard but with a different discord bot token?

winter garnet
nimble mist

Shards are the same bot only spread across different processes/workers. Different token is different bot

serene shell
terse cairn

Hi, do you know how to get the number of the shard?

nimble mist
terse cairn

thanks

wise spear

how to use sharding manager in typescript z_paliaso

fierce compass

compile the typescript files into javascript, and pass the built file path in the ShardingManager constructor

wise spear

I received this error

fierce compass

seems like you're importing the ts files

coral dome

hii, i want to know which better internal djs sharding with sharding manager? MCF_WhiteFlat

nimble mist
vestal sluice

how can I check if all shards are spawned?

should I compare <Managar>.shards.size and <Manager>.totalShards

nimble mist

Depends on what you want it for. shards.size will equal totalShards only if you have only one ShardingManager running on one machine. And it will be equal after calling spawn(). The Shards won‘t be ready by then though.
If you simply want to do something once all shards are spawned (and logged in) then resolution of the Promise you get from ShardingManager#spawn() gets you that

vestal sluice
nimble mist
vestal sluice
nimble mist
vestal sluice

and i cant just await it since its no async function
no

@nimble mist this is the only thing i get

node:internal/process/promises:246
    triggerUncaughtException(err, true /* fromPromise */);

and it doesnt really help debuging

nimble mist
vestal sluice

yes

nimble mist

Then show your sharding code

vestal sluice
const config = require("@root/config.json");
const { ShardingManager } = require('discord.js');

const manager = new ShardingManager('./src/bot/index.js', { token: config.client.token });

manager.on('shardCreate', shard => console.log(`Shard ${shard.id}: launched`));
manager.spawn();

module.exports = manager;

it worked with 2 shards, but since i have 3 shards it throws that error

nimble mist
vestal sluice
nimble mist
vestal sluice
nimble mist
vestal sluice
nimble mist
vestal sluice
nimble mist
vestal sluice

yea thats why i asked wym

nimble mist
vestal sluice

but outside of the bot

nimble mist
vestal sluice

yes
i initially require it in my main file

nimble mist

Then that somewhere else obviously is the source of your error

vestal sluice

but its also used in other files

nimble mist
vestal sluice so how would I do this?

The way you currently have it the best way would be to pass the manager from your main file to any subtiles that need it. But to give you a definite answer I‘d need to know more than it‘s something else outside of the bot

nimble mist
vestal sluice

so the general structure is, theres a directory bots and some others, including routes which is used for an api and a dashboard

and the dashboard and api are running outside of the bot, and they use the manager to get a client object when necessary

nimble mist

Can you pass the manager from the main file to some function you have to start the dashboard? And same for API?

vestal sluice

i could save the manager in the express app i think, would that work?

vestal sluice

let me try

@nimble mist nope doesnt work, since the app instance is not even used in my routes because of the router and there doesnt seem to be a way to get the app from the router

so ex-and importing looks like the only way.. is there a way to not reshard every shard but still export the manager? or do you have a different idea?

@nimble mist ?

nimble mist
vestal sluice <@415588601120686091> ?

If you must import it in different files you could wrap the spawning of the ShardingManager in a function and export that too, call the function in your main file (or simply call spawn on the imported manager directly in your main file)

vestal sluice
nimble mist
vestal sluice

logging returns a right looking shardingManager though

works now, thank you very much

vestal sluice

after shard 0 and 1 are launched, it throws the SHARDING_IN_PROCESS error mentioned above

then continues with the other shards

and everythings normal after that

nimble mist

Best await it before even requiring the other files, if possible

vestal sluice

i used an IIFE function for the async if that matters

fathom birch

Hello, when I start my bot now it works until the second shard starts and I got an error that it took too long I set the timeout to 9999999999 but that also didn't help the bot just takes way longer I didn't get the error yet but it takes forever does someone know what the problem is? Everything worked before today tho and I changed nothing

const { ShardingManager } = require("discord.js");
require("dotenv").config();

// Create your ShardingManager instance
const manager = new ShardingManager("./main.js", {
    // for ShardingManager options see:
    // https://discord.js.org/#/docs/main/stable/class/ShardingManager
    totalShards: "auto",
    token: process.env.TOKEN
});

// Emitted when a shard is created
manager.on("shardCreate", (shard) => console.log(`Shard ${shard.id} launched`));

// Spawn your shards
manager.spawn({timeout: 9999999999})
nimble mist
vestal sluice
fathom birch
nimble mist
nimble mist
fathom birch
vestal sluice
nimble mist
nimble mist
nimble mist
vestal sluice

i think i found out that the error comes from the sharding file, because before that await its logging and then after it its only logging again after that error and after the shards are done spawning @nimble mist

i also sometimes get Error [SHARDING_READY_TIMEOUT]: Shard 0's Client took too long to become ready.

nimble mist
proud mortarBOT

Please add the following code to your code base outside of any other event listeners and provide the full log output relevant to your issue.

client
    .on("debug", console.log)
    .on("warn", console.log)

• Note: if you initialize your Client as bot or other identifiers you need to use these instead of client
• If the output is too long to post consider using a bin instead: gist | hasteb.in | sourceb.in | hastebin

vestal sluice
nimble mist

There’s your issue then. Shard 0 becomes ready, tries to ask Shard 1 and 2 but they‘re not ready yet…

vestal sluice
nimble mist
vestal sluice
charred arch
vestal sluice

what?

charred arch
vestal sluice

what error

charred arch

how to fix that i didn't understand what he said

vestal sluice

just read what he told me if it was the same error

charred arch
charred arch
vestal sluice

error has not always the same cause

charred arch
full nacelle

I have a sharding manager

const manager = new ShardingManager(botFile(), {
    execArgv: process.execArgv,
    totalShards: "auto",
    token: config.TOKEN,
    mode: "process",
})

// Shard Create Listener Here

manager.spawn();

// create extra shards

And after that I want to create more special shards with the manager.createShard() method but it's always saying Error SHARDING_ALREADY_SPAWNED: Already spawned x shards any idea how to fix this

nimble mist
full nacelle
nimble mist
full nacelle

But the code is the same

nimble mist

I get the feeling you don’t fully understand what shards are, they processes running the same bot with the same token, but each only serving a different subset of guilds. You can of course spawn another bot in your ShardingManager, but you‘d need to do it with new Client and providing the token to that clients login method.

waxen ember

Hey, how do I get the GuildMemberManager from a guild fetched from broadcastEval ?

worthy ridge

is there any way for shard to communicate with the master process? I'm trying to store a large variable in-memory but dont want to store it on every shard...

dense cape

Values that pass through broadcastEval must be json-serializable

midnight ore

So i just started up a discord bot, and ive never dealt with shards before. I tried googling but i couldnt find an answer. Is it possible to manually change a guild from one shard to another?

sonic bear

No

ancient cove

How I can transfer constant from sharding file (index.js) to main bot file (bot.js) (shard manager launching bot.js)

ancient cove

I need to log in Steam in sharding file (index.js) and then export steam client to all shards, then on each shard I can use this steam client.

full nacelle

Why is the Shard constructor private in typescript? I wanted to handle the shard creation myself

nimble mist
nimble mist
full nacelle Why is the Shard constructor private in typescript? I wanted to handle the shard...

Because shards need to be added to the ShardingManager if you want to use it. Therefore ShardingManager#create handles instantiating Shards and registers them with the managery But usually you wouldn’t even call that yourself but use the spawn method instead.
If you don’t want the Shard to be registered with the Manager you shouldn’t use the Shard class either, since they rely on each other. So I can’t really see why you‘d want to directly instantiate a Shard

ancient cove
heady isle

My one shard is having a very high ping and late response time, but on other shards it's normal, what to do?

nimble mist

Or have it in a particular shard and do broadcastEval to that shard

nimble mist
heady isle
nimble mist
nimble mist
heady isle

@nimble mist see this

nimble mist
heady isle
nimble mist
heady isle for what reasons?

How would I know, I don’t know your code/what your bot does. Listening to debug event and logging it would tell you more

terse cairn
C:\Users\k-van\Desktop\CoffeeBOT\node_modules\discord.js\src\sharding\Shard.js:166
        reject(new Error('SHARDING_READY_TIMEOUT', this.id));
               ^

Error [SHARDING_READY_TIMEOUT]: Shard 0's Client took too long to become ready.
    at Timeout.onTimeout (C:\Users\k-van\Desktop\CoffeeBOT\node_modules\discord.js\src\sharding\Shard.js:166:16)
    at listOnTimeout (node:internal/timers:559:17)
    at processTimers (node:internal/timers:502:7) {
  [Symbol(code)]: 'SHARDING_READY_TIMEOUT'
}

I've been getting this error for two days, I couldn't find the solution

summer egret

#rules 6. I'm also not the person to ask about sharding

nimble mist
terse cairn

how do i make timeout

unkempt goblet

Hi

Why is it not showing shard.id on console ??

proud mortarBOT
nimble mist
unkempt goblet

Because there is no event named shardCreator. It’s shardCreate

unkempt goblet

How to make like this??? @nimble mist

proud mortarBOT
nimble mist
unkempt goblet
proud mortarBOT
clear patio

the first error comes because replit is trash and it cant load the shards on time, you can set time out (you can see how to do it on the sharding guide) in order to avoid it
the second error comes because you have used a web port in the same time, which is incompatible with replit, you can avoid it by setting your web server port to 0

but again, sharding on replit will cause you a lot of problems and you will need to move to another platform

  • that to host a bot on replit is not a good idea
    so I advise you to not host your bot on replit @unkempt goblet
unkempt goblet
past heart

Hey guys, stupid question:
I was wrapping my head around having the bot deploying in a kubernetes cluster with multiples (n) nodes but that will spawn n processes and connections, I guess this is what sharding is for? Or there's a specific way to handle this usecase

dreamy forge

You could do it with kubernetes (complete overkill unless you have like 100k+ guilds) or use the sharding manager provided by djs (or one made by someone else, like Kurasuta)

terse cairn

How to get websocket ping for shards

Please ping while replying.

summer marsh
wet topaz

hosting and writing code are 2 different things. vs doesn't host anything

nimble mist
terse cairn

Thanks

winter garnet

Is there a way on Internal Sharding to know when a shard starts?

stiff gull
winter garnet
next plaza
drifting mortar

What's Wrong

dense cape
drifting mortar
drifting mortar

How i can define the shard

dense cape
drifting mortar

I mean i need to see how many shards in bot in code stats

dense cape

client.shard.count (when using ShardingManager)

drifting mortar

Oh thank you very much

Thats was i needed

charred arch

i do have both debug and warn

charred arch
dense cape

You have to wait abt 5.5 hrs

charred arch
dense cape

You have to wait a little over 5.5 more hours

charred arch

oof

dense cape

It tells you in the error

Will attempt another connection in ${time}ms

charred arch

💀

terse cairn

const { ShardingManager } = require('discord.js');

const manager = new ShardingManager('./bot.js', {
  totalShards: 2,
  token: process.env.token
});

manager.on('shardCreate', shard => console.log(`Launched shard ${shard.id}`));

manager.on("disconnect", async (shard) => {
  console.log(`[${new Date().toString().split(" ", 5).join(" ")}] Disconnected Shard #${shard.id}`)
})

manager.on("death", async (shard) => {
  // shards.spawn(shards.totalShards , 10000);
  console.log(`[${new Date().toString().split(" ", 5).join(" ")}] Killed Shard #${shard.id}`)
})

manager.spawn({ timeout: -1 })
  .catch(console.error); ``` @nimble mist
nimble mist
terse cairn
nimble mist
terse cairn
nimble mist
terse cairn
nimble mist
terse cairn

Ok

proud mortarBOT

Tag suggestion for @terse cairn:
To share long code snippets use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks.

terse cairn

I just wanted to ask for bin linkemoji_30

I did play twice A_thinking

But i don’t think this is the reason

nimble mist

Does your bot do anything else fancy?

terse cairn

Taking effort?

nimble mist
terse cairn

So I’ve to remove that one inside forloop

nimble mist

It wouldn’t cause your error though, because player just returns if you try the same resource it already plays

Do you get the same error when you don‘t shard (the event listener one)?

terse cairn

It was on replit that time

nimble mist
terse cairn
nimble mist
terse cairn
nimble mist
terse cairn
const client = new Client({
  shards: 'auto',
  intents: [```
terse cairn

@nimble mist it’s working until now.
that warn emits after a while, so how can i know that this will work?
And if it works, this mean the issue from where?