Opening handshake timeout

Hi, I'm testing my bot and i make reboots often. I have and Opening handshake has timed out when trying to launch client.login(<botToken>) method, not sure if it comes from me or the API for hitting rate limit or whatever. Resetting bot token does not help. Currently I emptied my node_modules folder to reinstall from fresh. Versions - discord.js : v14.14.1 - node : v20.10.0 Can someone help on this ? Some details below.
4 Replies
d.js toolkit
d.js toolkit4mo 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
CYPH ERZZ
CYPH ERZZ4mo ago
Uncaught Error Error: Opening handshake has timed out
at <anonymous> (z:\DiscordDeFi\node_modules\@discordjs\ws\node_modules\ws\lib\websocket.js:872:7)
at emit (events:514:28)
at emitRequestTimeout (_http_client:840:9)
at onceWrapper (events:628:28)
at emit (events:514:28)
at Socket._onTimeout (net:589:8)
at listOnTimeout (internal/timers:573:17)
at processTimers (internal/timers:514:7)
Uncaught Error Error: Opening handshake has timed out
at <anonymous> (z:\DiscordDeFi\node_modules\@discordjs\ws\node_modules\ws\lib\websocket.js:872:7)
at emit (events:514:28)
at emitRequestTimeout (_http_client:840:9)
at onceWrapper (events:628:28)
at emit (events:514:28)
at Socket._onTimeout (net:589:8)
at listOnTimeout (internal/timers:573:17)
at processTimers (internal/timers:514:7)
Enabling debug like this :
this.client.on('debug', console.debug);
this.client.on('debug', console.debug);
Gives this :
[WS => Manager] Session Limit Information
Total: 1000
Remaining: 994
WebSocketManager.js:125
[WS => Shard 0] Connecting to wss://gateway.discord.gg?v=10&encoding=json
WebSocketManager.js:125
[WS => Shard 0] Waiting for event hello for 60000ms
WebSocketManager.js:125
[WS => Shard 0] The gateway closed with an unexpected code 1006, attempting to resume.
WebSocketManager.js:125
[WS => Shard 0] Destroying shard
Reason: none
Code: 1006
Recover: Resume
WebSocketManager.js:125
[WS => Shard 0] Connection status during destroy
Needs closing: false
Ready state: 3
WebSocketManager.js:125
[WS => Shard 0] Tried to destroy a shard that was idle
WebSocketManager.js:125
[WS => Manager] Manager was destroyed:
at WebSocketManager.destroy (Z:\DiscordDeFi\node_modules\discord.js\src\client\websocket\WebSocketManager.js:327:30)
at Client.destroy (Z:\DiscordDeFi\node_modules\discord.js\src\client\Client.js:253:19)
at Client.login (Z:\DiscordDeFi\node_modules\discord.js\src\client\Client.js:231:18)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
WebSocketManager.js:125
[WS => Shard 0] Tried to destroy a shard that was idle
Uncaught Error Error: Opening handshake has timed out
at <anonymous> (z:\DiscordDeFi\node_modules\@discordjs\ws\node_modules\ws\lib\websocket.js:872:7)
at emit (events:514:28)
at emitRequestTimeout (_http_client:840:9)
at onceWrapper (events:628:28)
at emit (events:514:28)
at Socket._onTimeout (net:589:8)
at listOnTimeout (internal/timers:573:17)
at processTimers (internal/timers:514:7)
[WS => Manager] Session Limit Information
Total: 1000
Remaining: 994
WebSocketManager.js:125
[WS => Shard 0] Connecting to wss://gateway.discord.gg?v=10&encoding=json
WebSocketManager.js:125
[WS => Shard 0] Waiting for event hello for 60000ms
WebSocketManager.js:125
[WS => Shard 0] The gateway closed with an unexpected code 1006, attempting to resume.
WebSocketManager.js:125
[WS => Shard 0] Destroying shard
Reason: none
Code: 1006
Recover: Resume
WebSocketManager.js:125
[WS => Shard 0] Connection status during destroy
Needs closing: false
Ready state: 3
WebSocketManager.js:125
[WS => Shard 0] Tried to destroy a shard that was idle
WebSocketManager.js:125
[WS => Manager] Manager was destroyed:
at WebSocketManager.destroy (Z:\DiscordDeFi\node_modules\discord.js\src\client\websocket\WebSocketManager.js:327:30)
at Client.destroy (Z:\DiscordDeFi\node_modules\discord.js\src\client\Client.js:253:19)
at Client.login (Z:\DiscordDeFi\node_modules\discord.js\src\client\Client.js:231:18)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
WebSocketManager.js:125
[WS => Shard 0] Tried to destroy a shard that was idle
Uncaught Error Error: Opening handshake has timed out
at <anonymous> (z:\DiscordDeFi\node_modules\@discordjs\ws\node_modules\ws\lib\websocket.js:872:7)
at emit (events:514:28)
at emitRequestTimeout (_http_client:840:9)
at onceWrapper (events:628:28)
at emit (events:514:28)
at Socket._onTimeout (net:589:8)
at listOnTimeout (internal/timers:573:17)
at processTimers (internal/timers:514:7)
Here's my entrypoint :
import DiscordClient from "./modules/discord/DiscordClient.mjs";

DiscordClient.initializeCommands();
DiscordClient.registerEventHandlers();
DiscordClient.login();
import DiscordClient from "./modules/discord/DiscordClient.mjs";

DiscordClient.initializeCommands();
DiscordClient.registerEventHandlers();
DiscordClient.login();
And my DiscordClient class :
import { Client, GatewayIntentBits, Partials, Collection, Events } from 'discord.js';
import fs from 'fs';
import appRootPath from 'app-root-path';
import { discord as discordConfig } from '../../config.mjs';

class DiscordClient {
constructor() {
this.client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent
],
partials: [
Partials.Channel,
Partials.Message
]
});
this.commands = new Collection();
}

async initializeCommands() {
const modulesPath = appRootPath.path + '/modules/discord/commands/';
const commandFiles = fs.readdirSync(modulesPath).filter(file => file.endsWith('.command.mjs'));

for (const file of commandFiles) {
const module = await import(`./commands/${file}`)
const command = module.default;
this.commands.set(command.data.name, command);
}
}
import { Client, GatewayIntentBits, Partials, Collection, Events } from 'discord.js';
import fs from 'fs';
import appRootPath from 'app-root-path';
import { discord as discordConfig } from '../../config.mjs';

class DiscordClient {
constructor() {
this.client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent
],
partials: [
Partials.Channel,
Partials.Message
]
});
this.commands = new Collection();
}

async initializeCommands() {
const modulesPath = appRootPath.path + '/modules/discord/commands/';
const commandFiles = fs.readdirSync(modulesPath).filter(file => file.endsWith('.command.mjs'));

for (const file of commandFiles) {
const module = await import(`./commands/${file}`)
const command = module.default;
this.commands.set(command.data.name, command);
}
}
registerEventHandlers() {
this.client.once(Events.ClientReady, async () => {
console.log('Discord bot is online!');
const commands = this.commands.map(command => command.data.toJSON());
try {
for (const guildId of discordConfig.guildIds) {
await this.client.application.commands.set(commands, guildId);
console.log(`Successfully registered slash commands for guild ID: ${guildId}`);
}
} catch (error) {
console.error('Error registering commands:', error);
}
});

this.client.on(Events.InteractionCreate, async interaction => {
if (interaction.guildId && !discordConfig.guildIds.includes(interaction.guildId)) {
return;
}

if (interaction.isCommand()) {
const command = this.commands.get(interaction.commandName);
if (!command) return;

try {
await command.execute(interaction);
} catch (error) {
console.error('Command execution error:', error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});

this.client.on('rateLimit', (info) => {
console.log(`Rate limit hit ${info.timeDifference ? info.timeDifference : info.timeout ? info.timeout : 'Unknown timeout '}`);
});

this.client.on(Events.Error, (error) => {
console.error('Error from the Discord API:', error);
});

this.client.on('debug', console.debug);

}

login() {
this.client.login(discordConfig.botToken);
}
}

const discordBot = new DiscordClient();
export default discordBot
registerEventHandlers() {
this.client.once(Events.ClientReady, async () => {
console.log('Discord bot is online!');
const commands = this.commands.map(command => command.data.toJSON());
try {
for (const guildId of discordConfig.guildIds) {
await this.client.application.commands.set(commands, guildId);
console.log(`Successfully registered slash commands for guild ID: ${guildId}`);
}
} catch (error) {
console.error('Error registering commands:', error);
}
});

this.client.on(Events.InteractionCreate, async interaction => {
if (interaction.guildId && !discordConfig.guildIds.includes(interaction.guildId)) {
return;
}

if (interaction.isCommand()) {
const command = this.commands.get(interaction.commandName);
if (!command) return;

try {
await command.execute(interaction);
} catch (error) {
console.error('Command execution error:', error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});

this.client.on('rateLimit', (info) => {
console.log(`Rate limit hit ${info.timeDifference ? info.timeDifference : info.timeout ? info.timeout : 'Unknown timeout '}`);
});

this.client.on(Events.Error, (error) => {
console.error('Error from the Discord API:', error);
});

this.client.on('debug', console.debug);

}

login() {
this.client.login(discordConfig.botToken);
}
}

const discordBot = new DiscordClient();
export default discordBot
Note that this module is imported in a command sub-module too, but not calling anything, it's just used to get the native this.client to retrieve a user object from a userID I think i fucked up something because even when it starts, sometime my commands are not registered, even if it shows a successfull registration in the logs. If you come here thank you for taking the time ❤️ :blobreachReverse: Bot's back online but i changed nothing so i guess it's temporary... until next reboot Nah i'm hosting it myself, own server, own internet connection. That's terrifying lol, hope it's not or it's because i fucked up at one point and made too many requests but it's temporary
d.js docs
d.js docs4mo ago
:discord: Rate Limits - Invalid Request Limit aka CloudFlare bans read more
CYPH ERZZ
CYPH ERZZ4mo ago
Thanks man, i'll monitor this I made a circular reference yesterday night, perhaps that's it