DarkstarDraconis
DarkstarDraconis
DIAdiscord.js - Imagine an app
Created by DarkstarDraconis on 5/7/2024 in #djs-questions
Deno / Websocket error
To start with, as I understand it, Deno is not officially supported. That said, from what I have been reading, it seemed like there was a reasonable chance of djs working with Deno since it added support for npm packages. I would really like to use Deno for my bot, so I gave it a go... Unfortunately, no dice -- I'm getting an error when djs is attempting to construct a WebSocket. I'm wondering if this is a familiar problem, or if anyone has an idea for what may be a fix for this. Here is the error when I attempt to run (I use "deno task simple" to run it):
error: Uncaught (in promise) SyntaxError: Invalid protocol value.
at new WebSocket (ext:deno_websocket/01_websocket.js:203:13)
at WebSocketShard.internalConnect (file:///Users/redacted/Library/Caches/deno/npm/registry.npmjs.org/@discordjs/ws/1.1.0/dist/index.js:675:24)
at eventLoopTick (ext:core/01_core.js:168:7)
error: Uncaught (in promise) SyntaxError: Invalid protocol value.
at new WebSocket (ext:deno_websocket/01_websocket.js:203:13)
at WebSocketShard.internalConnect (file:///Users/redacted/Library/Caches/deno/npm/registry.npmjs.org/@discordjs/ws/1.1.0/dist/index.js:675:24)
at eventLoopTick (ext:core/01_core.js:168:7)
deno.json
{
"tasks": {
"simple": "deno run --allow-env --allow-read --allow-net --watch ./src/simple_main.ts"
},
"imports": {
"discord.js": "npm:discord.js@^14.15.2",
"dotenv": "npm:dotenv@^16.4.5"
}
}
{
"tasks": {
"simple": "deno run --allow-env --allow-read --allow-net --watch ./src/simple_main.ts"
},
"imports": {
"discord.js": "npm:discord.js@^14.15.2",
"dotenv": "npm:dotenv@^16.4.5"
}
}
simple_main.ts
import { Client } from "npm:discord.js";
import dotenv from "npm:dotenv";

dotenv.config();

const client = new Client({ intents: [] });

await client.login(Deno.env.get('TOKEN'))
.then(() => {
console.log(`🟩 [LOGIN] Client logged!`);
})
.catch((err) => console.error(`🟥 [LOGIN] ${err}`));
import { Client } from "npm:discord.js";
import dotenv from "npm:dotenv";

dotenv.config();

const client = new Client({ intents: [] });

await client.login(Deno.env.get('TOKEN'))
.then(() => {
console.log(`🟩 [LOGIN] Client logged!`);
})
.catch((err) => console.error(`🟥 [LOGIN] ${err}`));
The error is pointing at index.js in djs, which is doing this:
const connection = new WebSocketConstructor(url, {
handshakeTimeout: this.strategy.options.handshakeTimeout ?? void 0
});
const connection = new WebSocketConstructor(url, {
handshakeTimeout: this.strategy.options.handshakeTimeout ?? void 0
});
The tooltip is telling me arg2 should be a string | string[] | undefined which is probably why the underlying code is throwing the error. Again, I understand there isn't any official support, but if there's a workaround for this that allows me to continue using Deno, I would appreciate any ideas. In case it matters, deno --version:
deno 1.43.1 (release, x86_64-apple-darwin)
v8 12.4.254.12
typescript 5.4.3
deno 1.43.1 (release, x86_64-apple-darwin)
v8 12.4.254.12
typescript 5.4.3
39 replies