Cannot use 'in' operator to search for 'code' in undefined

When running my bot it sometimes returns this error and exists
error: Uncaught TypeError: Cannot use 'in' operator to search for 'code' in undefined
at WebSocketShard.onError (file:///deno-dir/npm/registry.npmjs.org/@discordjs/ws/1.1.1/dist/index.js:1065:16)
at WebSocket.connection.onerror (file:///deno-dir/npm/registry.npmjs.org/@discordjs/ws/1.1.1/dist/index.js:683:12)
at WebSocket.wrappedHandler (ext:deno_web/02_event.js:1401:12)
at innerInvokeEventListeners (ext:deno_web/02_event.js:754:7)
at invokeEventListeners (ext:deno_web/02_event.js:801:5)
at dispatch (ext:deno_web/02_event.js:658:9)
at WebSocket.dispatchEvent (ext:deno_web/02_event.js:1043:12)
at WebSocket.[[[eventLoop]]] (ext:deno_websocket/01_websocket.js:481:16)
at eventLoopTick (ext:core/01_core.js:168:7)
error: Uncaught TypeError: Cannot use 'in' operator to search for 'code' in undefined
at WebSocketShard.onError (file:///deno-dir/npm/registry.npmjs.org/@discordjs/ws/1.1.1/dist/index.js:1065:16)
at WebSocket.connection.onerror (file:///deno-dir/npm/registry.npmjs.org/@discordjs/ws/1.1.1/dist/index.js:683:12)
at WebSocket.wrappedHandler (ext:deno_web/02_event.js:1401:12)
at innerInvokeEventListeners (ext:deno_web/02_event.js:754:7)
at invokeEventListeners (ext:deno_web/02_event.js:801:5)
at dispatch (ext:deno_web/02_event.js:658:9)
at WebSocket.dispatchEvent (ext:deno_web/02_event.js:1043:12)
at WebSocket.[[[eventLoop]]] (ext:deno_websocket/01_websocket.js:481:16)
at eventLoopTick (ext:core/01_core.js:168:7)
I am running the bot in a deno docker container. Bot code:
import { Client, Events, GuildMember } from "discord";

const client = new Client({
// Numbers since the GatewayIntentBits import does not work in deno for some reason
intents: [
1,
2,
4,
512,
1024,
4096,
32768,
16777216,
33554432
]
});

client.on(Events.GuildMemberAdd, (member: GuildMember) => {
member.roles.add("1205218206155935754", "Join role");
});

client.login(Deno.env.get("TOKEN"));
import { Client, Events, GuildMember } from "discord";

const client = new Client({
// Numbers since the GatewayIntentBits import does not work in deno for some reason
intents: [
1,
2,
4,
512,
1024,
4096,
32768,
16777216,
33554432
]
});

client.on(Events.GuildMemberAdd, (member: GuildMember) => {
member.roles.add("1205218206155935754", "Join role");
});

client.login(Deno.env.get("TOKEN"));
3 Replies
d.js toolkit
d.js toolkit5mo 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!
Kay
KayOP5mo ago
is there a way to debug or fix this?
GitHub
GitHub5mo ago
:issue_open: #10327 in discordjs/discord.js by NeuroWhAI opened <t:1717653636:R> ws throws TypeError: Cannot use 'in' operator to search for 'code' in undefined when with Deno
Want results from more Discord servers?
Add your server