discord-optimizer
Version:
Reduce Discord.js bot RAM usage with automatic optimization and restart capabilities
32 lines • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.clearDiscordCaches = clearDiscordCaches;
exports.performOptimizations = performOptimizations;
const memoryUtils_1 = require("./memoryUtils");
function clearDiscordCaches(client) {
client.guilds.cache.forEach(guild => {
guild.channels.cache.forEach(channel => {
if (channel.isTextBased() && 'messages' in channel) {
channel.messages.cache.clear();
}
});
});
const importantUsers = new Set();
client.guilds.cache.forEach(guild => {
guild.members.cache.forEach(member => {
if (member.permissions.has('Administrator') || member.user.bot) {
importantUsers.add(member.user.id);
}
});
});
client.users.cache.sweep(user => !importantUsers.has(user.id));
}
function performOptimizations(client, options) {
if (options.clearCache) {
clearDiscordCaches(client);
}
if (options.garbageCollect) {
(0, memoryUtils_1.forceGarbageCollection)();
}
}
//# sourceMappingURL=optimizations.js.map