Hello everyone,
I'm currently developing a Discord bot that's active on approximately 1,200 servers, with some servers exceeding 20,000 members. The bot generates a significant number of logs, which is beneficial for monitoring and moderation purposes. However, I've encountered issues related to user data caching: certain user information, such as profile pictures or usernames, becomes outdated because those users aren't present in the cache.
I'm seeking strategies to optimize the bot's overall cache management. Specifically, I'm interested in:
Limiting the cache to store only specific keys or properties of objects.
Implementing more efficient caching mechanisms to ensure up-to-date user information without overloading the system.
I've reviewed the Discord.js documentation on cache customization, including the use of makeCache and Options.cacheWithLimits . While these resources are helpful, I'm looking for additional insights or best practices from the community.
Has anyone faced similar challenges or implemented effective solutions for managing cache in large-scale bots? Any advice or examples would be greatly appreciated.
Thank you in advance!
{
shardCount: parseInt(process.env.SHARD_COUNT), // 3 shard
shards: parseInt(process.env.SHARDS_ID),
failIfNotExists: false,
intents: [GatewayIntentBits.AutoModerationExecution, GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.DirectMessages, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildModeration, GatewayIntentBits.GuildEmojisAndStickers, GatewayIntentBits.GuildInvites, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildPresences, GatewayIntentBits.MessageContent],
partials: [
Partials.Message,
Partials.Reaction,
Partials.Channel,
Partials.User,
],
presence: {
status: "dnd",
activities: [{ name: `v${version} | Shard n°${process.env.SHARDS_ID}`, type: ActivityType.Custom }]
},
sweepers: {
...Options.DefaultSweeperSettings,
messages: {
interval: 1300,
lifetime: 108000,
filter: () => (message) => {
if (!message.guildId) return true;
if (message?.author?.bot && message?.author?.id != message.client.user.id) return true;
if (message?.webhookId) return true;
if (message?.author?.id == message.client.user.id && message.createdTimestamp < (Date.now() - 1800000)) return true;
return false;
}
},
users: {
interval: 3600,
filter: () => (user) => {
return user.bot
},
},
guildMembers: {
interval: 1300,
filter: () => (member) => {
return (member.user.bot && member?.user?.id !== member?.client?.user?.id)
}
}
},
makeCache: Options.cacheWithLimits({
ReactionManager: 100,
ReactionUserManager: 100,
ThreadManager: 0,
ThreadMemberManager: 0,
GuildScheduledEventManager: 0,
GuildTextThreadManager: 0,
GuildForumThreadManager: 0,
GuildMemberManager: {
maxSize: 5000,
keepOverLimit: member => member.id === member.client.user.id,
},
UserManager: {
maxSize: 1000,
keepOverLimit: user => user.id === user.client.user.id,
}
})
}