It seems that my <ShardingManager>.spawn() is calling itself in a loop and I'm not sure why. I followed the getting started article on the Discord.js guide website. My Discord.js version is 13.0.6. I have also tried using a different Discord application token but that didn't help either.
It looks as if index.js is being executed multiple times, and I'm not sure why.
Here's my setup:
index.ts:
import { Application } from './Application';
export const application = new Application();
application.initSharding();
Application.ts:
import { ShardingManager } from 'discord.js';
import dotenv from 'dotenv';
import path from 'path';
export class Application {
public async initSharding() {
const shardingManager = new ShardingManager('./build/Shard.js', {
token: process.env.DISCORD_TOKEN,
});
shardingManager.on('shardCreate', shard => {
console.log(`[SHARDING MANAGER] LAUNCHED SHARD ${shard.id}`);
});
await shardingManager.spawn().catch(reason => console.log(reason));
}
constructor() {
dotenv.config({ path: path.resolve(__dirname, '../variables.env') });
}
}
Shard.ts:
import { Client, Intents } from 'discord.js';
import { application } from '.';
import { Utils } from './Utils';
export class Shard {
private _client: Client;
constructor() {
this._client = new Client({
intents: [Intents.FLAGS.GUILDS],
});
this._client.login(process.env.DISCORD_TOKEN).catch(reason => console.log(reason));
}
}
new Shard();
I eventually get the following error:
RESPONSE {
SIZE: 0,
TIMEOUT: 0,
[SYMBOL(BODY INTERNALS)]: {
BODY: PASSTHROUGH {
_READABLESTATE: [READABLESTATE],
_EVENTS: [OBJECT: NULL PROTOTYPE],
_EVENTSCOUNT: 2,
_MAXLISTENERS: UNDEFINED,
_WRITABLESTATE: [WRITABLESTATE],
ALLOWHALFOPEN: TRUE,
[SYMBOL(KCAPTURE)]: FALSE,
[SYMBOL(KCALLBACK)]: NULL
},
DISTURBED: FALSE,
ERROR: NULL
},
[SYMBOL(RESPONSE INTERNALS)]: {
URL: 'HTTPS://DISCORD.COM/API/V9/GATEWAY/BOT',
STATUS: 429,
STATUSTEXT: 'TOO MANY REQUESTS',
HEADERS: HEADERS { [SYMBOL(MAP)]: [OBJECT: NULL PROTOTYPE] },
COUNTER: 0
}
}
Any help is appreciated.