shards: "auto",
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages
],
presence: {
status: 'online',
activities: [{ name: '/help', type: ActivityType.Listening }],
},
makeCache: (manager) => {
if (necessaryManagers.includes(manager.name)) {
return new Collection();
}
if (userRelatedManagers.includes(manager.name)) {
return new Collection();
}
return new LimitedCollection({ maxSize: 0 });
},
sweepers: {
guildMembers: {
interval: 2700,
lifetime: 1200,
filter: () => member => member.id !== bot.user.id
},
users: {
interval: 2700,
lifetime: 1200,
filter: () => member => member.id !== bot.user.id
},
channels: {
interval: 2700,
lifetime: 1200,
filter: () => channel => true
},
guildChannels: {
interval: 2700,
lifetime: 1200,
filter: () => channel => true
},
roles: {
interval: 2700,
lifetime: 1200,
filter: () => role => true
},
guilds: {
interval: 2700,
lifetime: 1200,
filter: () => guild => true
},
permissionOverwrites: {
interval: 2700,
lifetime: 1200,
filter: () => permissionOverwrite => true
},
voiceStates: {
interval: 2700,
lifetime: 1200,
filter: () => voiceState => true
}
}
});```
this is my constructor, i was told that it's possible to do worker mode with internal sharding to make it more efficient, how do i do that?
version: 14.16.2
#sharding with workers
15 messages · Page 1 of 1 (latest)
- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - Not a discord.js issue? Check out #1081585952654360687.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
one thing, you should not sweep guild, channels and roles. It breaks functionality and is unsupported, hence the big red warning
You want to specify mode: "worker" in the ShardingManager options
ShardingManager @14.16.3
This is a utility class that makes multi-process sharding of a bot an easy and painless experience. It works by spawning a self-contained ChildProcess or Worker for each individual shard, each containing its own instance of your bot's Client. They all have a line of communication with the master process, and there are several useful methods that utilise it in order to simplify tasks that are normally difficult with sharding. It can spawn a specific number of shards or the amount that Discord suggests for the bot, and takes a path to your main bot script to launch for each one.
(manager) => new WorkerShardingStrategy(manager, { shardsPerWorker: 2 })
That would be an example for the <ClientOptions>.ws.buildStrategy function
So this would be correct right?:
const bot = new Client({
shards: "auto",
ws: {
buildStrategy: (manager) => new WorkerShardingStrategy(manager, { shardsPerWorker: 2 })
},
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildMessages
],
presence: {
status: 'online',
activities: [{ name: '/help', type: ActivityType.Listening }],
},
makeCache: (manager) => {
if (necessaryManagers.includes(manager.name)) {
return new Collection();
}
if (userRelatedManagers.includes(manager.name)) {
return new Collection();
}
return new LimitedCollection({ maxSize: 0 });
},
sweepers: {
guildMembers: {
interval: 2700,
lifetime: 1200,
filter: () => member => member.id !== bot.user.id
},
users: {
interval: 2700,
lifetime: 1200,
filter: () => member => member.id !== bot.user.id
},
permissionOverwrites: {
interval: 2700,
lifetime: 1200,
filter: () => permissionOverwrite => true
},
voiceStates: {
interval: 2700,
lifetime: 1200,
filter: () => voiceState => true
}
}
});```
That's all i need to modify for this to work?
Yes (assuming you want one worker per shards)
Well one worker per shard is fine right? also i dont need to make another file or something, this is all?
Sharding: Getting started - Sharding file