Assistance in setting up makeCache and sweepers

Hello, I would like Assistance in setting up makeCache and sweepers. My problem: I have a certain amount of cpu/ram usage available to my bot, because that is what my host allows me / what I pay for atm, and the server cpu usage reaches 100% after 1.5 days of my bot being online. My bot is in 1.3k servers and does basically only music related stuff. This is my custom client class: https://sourceb.in/nEXUlqZDs5 I use the npm package "status-sharding" for sharding which allows for makeCache etc. since it does not interfere with djs. I would like to achieve a sweeping cache so that after inactivity, the cache gets cleared for every guild (members, channels, messages etc.) after a certain amount of time. Also is limiting the cache to 100 messages/channel too much? Do I even need that/other value for that? I use mainly this in my bot to get stuff: const guild = bot.guilds.cache.get(id) || (await bot.guilds.fetch(id).catch(() => {})); same for channel and messages etc. djs version: 14.16.2 node version: v20.17.0
6 Replies
d.js toolkit
d.js toolkit3mo 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
notvexi
notvexiOP3mo ago
ok ty and what about makeCache? Are there any things I can just remove like I dont need emoji caching if thats a default thing - member.roles.cache.has(roleID) - guild.members.cache.get(userID) - bot.channels.cache.get(channelID) - channel.messages.cache.get(messageID) - bot.guilds.cache.size/forEach/other stuff - guild.channels.cache is what I use in my bot
d.js docs
d.js docs3mo ago
:interface: Caches @14.16.3
notvexi
notvexiOP3mo ago
so is this fine?
makeCache: Options.cacheWithLimits({
MessageManager: {
maxSize: 100,
keepOverLimit: (message) => message.author.id === this.user.id,
},
GuildMemberManager: {
maxSize: 150,
keepOverLimit: (member) => member.id === this.user.id || member.roles.cache.size > 0,
},
UserManager: {
maxSize: 100,
},
}),
messageCacheLifetime: 1000 * 60 * 20, // also is this a thing?
makeCache: Options.cacheWithLimits({
MessageManager: {
maxSize: 100,
keepOverLimit: (message) => message.author.id === this.user.id,
},
GuildMemberManager: {
maxSize: 150,
keepOverLimit: (member) => member.id === this.user.id || member.roles.cache.size > 0,
},
UserManager: {
maxSize: 100,
},
}),
messageCacheLifetime: 1000 * 60 * 20, // also is this a thing?
ye i noticed that also xd okay thanks a lot also i am dumb but what is "Options.DefaultSweeperSettings" and "Options.DefaultMakeCacheSettings"? where can i see the values they pass
d.js docs
d.js docs3mo ago
:property: (static) Options#DefaultMakeCacheSettings @14.16.3 The default settings passed to makeCache. The caches that this changes are:* MessageManager - Limit to 200 messages If you want to keep default behavior and add on top of it you can use this object and add on to it, e.g. makeCache: Options.cacheWithLimits({ ...Options.DefaultMakeCacheSettings, ReactionManager: 0 }) :property: (static) Options#DefaultSweeperSettings @14.16.3 The default settings passed to sweepers. The sweepers that this changes are:* threads - Sweep archived threads every hour, removing those archived more than 4 hours ago If you want to keep default behavior and add on top of it you can use this object and add on to it, e.g. sweepers: { ...Options.DefaultSweeperSettings, messages: { interval: 300, lifetime: 600 } }
notvexi
notvexiOP3mo ago
thanks
Want results from more Discord servers?
Add your server