denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
94.63k stars 5.25k forks source link

Discord.js still not working #20761

Open foufrix opened 1 year ago

foufrix commented 1 year ago

Hi

I saw that there was an update to make WebSocket works better, and by that allowing the use of discord.js

I quickly tried with a small connection example deno-test.ts

import { load } from 'https://deno.land/std@0.202.0/dotenv/mod.ts';
import { Client, Events, GatewayIntentBits } from 'discord.js';

const env = await load();
const discordToken = env['DISCORD_BOT_TOKEN'];

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

client.once(Events.ClientReady, (c) => {
  console.log(`Ready! Logged in as ${c.user.tag}`);
});

client.login(discordToken); // a valid token

And I have this error :

deno run src/deno-test.ts                                                                                                                                                                                                                             [23/10/2| 5:40]
✅ Granted all read access.
✅ Granted all ffi access.
✅ Granted all net access.
Warning: Not implemented: ClientRequest.options.createConnection
✅ Granted all env access.
error: Uncaught (in promise) Error: Invalid WebSocket frame: invalid UTF-8 sequence
    at Receiver.dataMessage (file:///Users/raf/Documents/PiNGS/discord-bot/node_modules/.deno/ws@8.14.2/node_modules/ws/lib/receiver.js:551:18)
    at Receiver.getData (file:///Users/raf/Documents/PiNGS/discord-bot/node_modules/.deno/ws@8.14.2/node_modules/ws/lib/receiver.js:478:17)
    at Receiver.startLoop (file:///Users/raf/Documents/PiNGS/discord-bot/node_modules/.deno/ws@8.14.2/node_modules/ws/lib/receiver.js:167:22)
    at Receiver._write (file:///Users/raf/Documents/PiNGS/discord-bot/node_modules/.deno/ws@8.14.2/node_modules/ws/lib/receiver.js:93:10)
    at writeOrBuffer (ext:deno_node/_stream.mjs:3948:16)
    at _write (ext:deno_node/_stream.mjs:3893:14)
    at Receiver.Writable.write (ext:deno_node/_stream.mjs:3896:14)
    at Socket.socketOnData (file:///Users/raf/Documents/PiNGS/discord-bot/node_modules/.deno/ws@8.14.2/node_modules/ws/lib/websocket.js:1286:35)
    at Socket.emit (ext:deno_node/_stream.mjs:1852:9)
    at addChunk (ext:deno_node/_stream.mjs:2874:16)

And this is my current config :

```bash
deno --version                                                                                                                                                                                                                                        
deno 1.37.1 (release, aarch64-apple-darwin)
v8 11.8.172.6
typescript 5.2.2

I have a Mackbook Air M1. Anyone managing to run discord.js on post deno v1.35? Do I need to do something else to make it work?

Sunf3r commented 12 months ago

Discord.JS is working fine for me. Try using 'npm:discord.js'on your import

image

my code:

import { config } from 'https://deno.land/x/dotenv@v3.2.0/mod.ts';
import { Client, Interaction } from 'npm:discord.js';

// Setup environment variables
config({ export: true });

const bot = new Client({ // build client
    intents: ['Guilds'],
});

bot // add listeneners
    .once('ready', (b) => console.log(`Logged in as ${b.user.tag}`))
    .on('interactionCreate', (i: Interaction) => {
        if (!i.isChatInputCommand()) return;
        // ignore non-command interactions

        // reply cmd
        i.reply('a');
    });

bot.login(Deno.env.get('DISCORD_TOKEN'));
foufrix commented 11 months ago

Hi @Sunf3r thank you for the reply

I have the same error using exactly your code, that's strange. (red line are only because it's a Typescript env)

image

What do you have running deno --version? Are you on mac silicon as well?