-
Notifications
You must be signed in to change notification settings - Fork 254
Large RAM usage for a simple script #1737
Description
Which package has the bugs?
The core library
Issue description
Hello,
I'm encountering a significant memory usage increase when my user account remains connected to a voice channel for extended periods. The memory usage continues to rise over time, eventually causing the process to exceed the allocated memory limit and restart.
Steps to Reproduce:
Use a user token to log in.
Join a voice channel and remain connected.
Monitor memory usage over time.
Expected Behavior:
The memory usage should remain stable without significant increases.
Actual Behavior:
Memory usage increases steadily, leading to process restarts.
Environment:
Node.js version: v22.16.0
discord.js-selfbot-v13
Operating System: Linux
Additional Information:
I've attempted to minimize caching and event listeners, but the issue persists. Any insights or recommendations would be greatly appreciated.
Thank you for your time and assistance.
Code sample
import { Client, Options } from 'discord.js-selfbot-v13';
import { joinVoiceChannel, getVoiceConnection, VoiceConnectionStatus, entersState } from '@discordjs/voice';
const cfg = {
token: 'YOUR_TOKEN',
voiceChannelId: 'VOICE_CHANNEL_ID',
selfDeaf: false,
selfMute: false,
reconnect: { delayMs: 5000, readyTimeoutMs: 15000 }
};
const client = new Client({
makeCache: Options.cacheWithLimits({
GuildMemberManager: 0,
MessageManager: 0,
UserManager: 0
})
});
async function connectToVoice() {
const channel = await client.channels.fetch(cfg.voiceChannelId).catch(() => null);
if (!channel || !channel.isVoice()) return;
const guildId = channel.guild.id;
let conn = getVoiceConnection(guildId);
if (!conn) {
conn = joinVoiceChannel({
channelId: channel.id,
guildId,
adapterCreator: channel.guild.voiceAdapterCreator,
selfDeaf: cfg.selfDeaf,
selfMute: cfg.selfMute
});
}
conn.removeAllListeners(VoiceConnectionStatus.Disconnected);
conn.removeAllListeners('error');
conn.setMaxListeners(10);
conn.on(VoiceConnectionStatus.Disconnected, async () => {
try {
await entersState(conn, VoiceConnectionStatus.Signalling, cfg.reconnect.delayMs);
await entersState(conn, VoiceConnectionStatus.Connecting, cfg.reconnect.delayMs);
} catch {
conn.destroy();
setTimeout(connectToVoice, cfg.reconnect.delayMs);
}
});
conn.on('error', () => {});
await entersState(conn, VoiceConnectionStatus.Ready, cfg.reconnect.readyTimeoutMs);
}
client.once('ready', async () => {
await connectToVoice();
setInterval(() => {
const m = process.memoryUsage();
console.log(`Memory usage — rss: ${(m.rss / 1024 / 1024).toFixed(2)} MB, heapUsed: ${(m.heapUsed / 1024 / 1024).toFixed(2)} MB`);
}, 5000);
});
client.login(cfg.token);Package version
latest
Node.js version
v22.16.0
Operating system
linux
Priority this issue should have
High (immediate attention needed)
Checklist
- I have searched the open issues for duplicates.
- I have shared the entire traceback.
- I am using a user token (and it isn't visible in the code).
Additional Information
No response