Caching

Idk what do with caching anymore, I tried sweeping and tbh it doesnt work. I removed the call of messagecontent intents when initializing the bot and it significantly reduced memory usage from 400mb gradually growing over 12h to 190mb graduall growing over 12h both starting at 80mb of ram. So can i disable caching all together? Would that be inefficient. what else can i do here. sweeping is tbh dead. and no i dont have any memory leaks in my code. Or is there a way to sweep all cached stuff by discordjs instead of pointing out every thing to sweep? here is my code rn:
const bot = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildWebhooks,
],
sweepers: {
...Options.DefaultSweeperSettings,
messages: {
interval: 3_600, // Every hour.
lifetime: 1_800, // Remove messages older than 30 minutes.
},
},
});
const bot = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildWebhooks,
],
sweepers: {
...Options.DefaultSweeperSettings,
messages: {
interval: 3_600, // Every hour.
lifetime: 1_800, // Remove messages older than 30 minutes.
},
},
});
5 Replies
d.js toolkit
d.js toolkit6mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - 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! - Marked as resolved by OP
Lawa
Lawa6mo ago
node 18, discordjs 14.14.1 can i disable caching? if yes what are the consequences my bot needs to read/create webhooks and guilds isnt that needed for everything including webhooks messagecontent intent was added for a test command i dont really need it but the issue here is the ram gradually increasing for no reason im guessing the guilds intent is caching many guilds stuff? but there is no option to sweep guilds idk im lost what does the guild intent even cache so webhooks alright then im lost that makes sense i do send a lot of it shouldnt the messages sweep tho take care of it? alright will test that and come back after 12 to 14h ok sorry to bother but how do i exactly do that i cant seem to find the documentation ofit
d.js docs
d.js docs6mo ago
:guide: Miscellaneous: Cache customization - Limiting caches When creating a new Clientopen in new window, you can limit the size of caches, which are specific to certain managers, using the makeCache option. Generally speaking, almost all your customizations can be done via the helper functions from the Optionsopen in new window module. read more
Lawa
Lawa6mo ago
alright
const bot = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildWebhooks],
sweepers: {
...Options.DefaultSweeperSettings,
messages: {
interval: 3_600, // Every hour.
lifetime: 1_800, // Remove messages older than 30 minutes.
},
},
makeCache: Options.cacheWithLimits({
...Options.DefaultMakeCacheSettings,
MessageManager: 0,
}),
});
const bot = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildWebhooks],
sweepers: {
...Options.DefaultSweeperSettings,
messages: {
interval: 3_600, // Every hour.
lifetime: 1_800, // Remove messages older than 30 minutes.
},
},
makeCache: Options.cacheWithLimits({
...Options.DefaultMakeCacheSettings,
MessageManager: 0,
}),
});
here is my code ill deploy it and monitor ram usage yeah i guessed so fixed throwing something out there i can already see a big difference it starts now at 70mb instead of 80. Idk how that worked out but ill update this thread after 12h

makeCache: Options.cacheWithLimits({
...Options.DefaultMakeCacheSettings,
MessageManager: 0,
ReactionManager: 0,
VoiceStateManager: 0,
UserManager: 0,
ThreadMemberManager: 0,
ThreadManager: 0,
StageInstanceManager: 0,
ReactionUserManager: 0,
PresenceManager: 0,
GuildStickerManager: 0,
GuildScheduledEventManager: 0,
GuildInviteManager: 0,
GuildBanManager: 0,
GuildMemberManager: 0,
GuildEmojiManager: 0,
BaseGuildEmojiManager: 0,
AutoModerationRuleManager: 0,
ApplicationCommandManager: 0,
}),

makeCache: Options.cacheWithLimits({
...Options.DefaultMakeCacheSettings,
MessageManager: 0,
ReactionManager: 0,
VoiceStateManager: 0,
UserManager: 0,
ThreadMemberManager: 0,
ThreadManager: 0,
StageInstanceManager: 0,
ReactionUserManager: 0,
PresenceManager: 0,
GuildStickerManager: 0,
GuildScheduledEventManager: 0,
GuildInviteManager: 0,
GuildBanManager: 0,
GuildMemberManager: 0,
GuildEmojiManager: 0,
BaseGuildEmojiManager: 0,
AutoModerationRuleManager: 0,
ApplicationCommandManager: 0,
}),
all makeCache rules on my bot i only use
interaction.client.guilds.cache.size +
interaction.client.guilds.cache
.map((g) => g.memberCount)
.reduce((a, c) => a + c)
interaction.client.guilds.cache.size +
interaction.client.guilds.cache
.map((g) => g.memberCount)
.reduce((a, c) => a + c)
so i shouldnt worry about disabling all cache right? therre isnt any other functionalities that require it? nothing else that uses the cache Update: even with:
const bot = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildWebhooks],
makeCache: Options.cacheWithLimits({
...Options.DefaultMakeCacheSettings,
MessageManager: 0,
ReactionManager: 0,
VoiceStateManager: 0,
UserManager: 0,
ThreadMemberManager: 0,
ThreadManager: 0,
StageInstanceManager: 0,
ReactionUserManager: 0,
PresenceManager: 0,
GuildStickerManager: 0,
GuildScheduledEventManager: 0,
GuildInviteManager: 0,
GuildBanManager: 0,
GuildMemberManager: 0,
GuildEmojiManager: 0,
BaseGuildEmojiManager: 0,
AutoModerationRuleManager: 0,
ApplicationCommandManager: 0,
}),
});
const bot = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildWebhooks],
makeCache: Options.cacheWithLimits({
...Options.DefaultMakeCacheSettings,
MessageManager: 0,
ReactionManager: 0,
VoiceStateManager: 0,
UserManager: 0,
ThreadMemberManager: 0,
ThreadManager: 0,
StageInstanceManager: 0,
ReactionUserManager: 0,
PresenceManager: 0,
GuildStickerManager: 0,
GuildScheduledEventManager: 0,
GuildInviteManager: 0,
GuildBanManager: 0,
GuildMemberManager: 0,
GuildEmojiManager: 0,
BaseGuildEmojiManager: 0,
AutoModerationRuleManager: 0,
ApplicationCommandManager: 0,
}),
});
memory is still increasing now the code is nothing except bot.on('ready') and thats it, it does nothing it's even worse with these, without limiting everything it uses around 15mb less memory but still increases overtime im so lost here's the entire code:
require("dotenv").config();
const {
Client,
Options,
Events,
GatewayIntentBits,
ActivityType
} = require("discord.js");

const bot = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildWebhooks],
makeCache: Options.cacheWithLimits({
...Options.DefaultMakeCacheSettings,
MessageManager: 0,
ReactionManager: 0,
VoiceStateManager: 0,
UserManager: 0,
ThreadMemberManager: 0,
ThreadManager: 0,
StageInstanceManager: 0,
ReactionUserManager: 0,
PresenceManager: 0,
GuildStickerManager: 0,
GuildScheduledEventManager: 0,
GuildInviteManager: 0,
GuildBanManager: 0,
GuildMemberManager: 0,
GuildEmojiManager: 0,
BaseGuildEmojiManager: 0,
AutoModerationRuleManager: 0,
ApplicationCommandManager: 0,
}),
});

bot.once(Events.ClientReady, () => {
console.log(`ready`);
bot.user.setActivity({
name: "/help",
type: ActivityType.Watching,
})
});

bot.login(process.env.BOT_TOKEN);
require("dotenv").config();
const {
Client,
Options,
Events,
GatewayIntentBits,
ActivityType
} = require("discord.js");

const bot = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildWebhooks],
makeCache: Options.cacheWithLimits({
...Options.DefaultMakeCacheSettings,
MessageManager: 0,
ReactionManager: 0,
VoiceStateManager: 0,
UserManager: 0,
ThreadMemberManager: 0,
ThreadManager: 0,
StageInstanceManager: 0,
ReactionUserManager: 0,
PresenceManager: 0,
GuildStickerManager: 0,
GuildScheduledEventManager: 0,
GuildInviteManager: 0,
GuildBanManager: 0,
GuildMemberManager: 0,
GuildEmojiManager: 0,
BaseGuildEmojiManager: 0,
AutoModerationRuleManager: 0,
ApplicationCommandManager: 0,
}),
});

bot.once(Events.ClientReady, () => {
console.log(`ready`);
bot.user.setActivity({
name: "/help",
type: ActivityType.Watching,
})
});

bot.login(process.env.BOT_TOKEN);
it's using around 20mb more on startup too by limiting everything, So idk? what went wrong now it uses less memory with just
const bot = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildWebhooks],
makeCache: Options.cacheWithLimits({
...Options.DefaultMakeCacheSettings,
MessageManager: 0,
}),
});
const bot = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildWebhooks],
makeCache: Options.cacheWithLimits({
...Options.DefaultMakeCacheSettings,
MessageManager: 0,
}),
});
but it still increases overtime.
manikin
manikin6mo ago
on a sparkedhost server sorry this is my mobile account i cant currently reach my pc to reply with the other account i'm not home i own a lot of big servers and big bots and i split ownerships between accounts in case one gets compromised it's probably then just normal but i guess it reduced the ram significantly which is good. Thanks for the help i'll mark the ticket as solved when i get home...
Want results from more Discord servers?
Add your server