Skip to content

npm:discord.js hangs #17391

@ghaerdi

Description

@ghaerdi

Summary

I found a bug by trying to create a discord bot in Deno using the discord.js package from npm.
I ran the following code (replacing the empty string in the line 3):

import { Client, GatewayIntentBits, Events } from "npm:discord.js";

const TOKEN = "" // replace empty string with a discord bot's token;

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

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

client.on(Events.InteractionCreate, async (interaction) => {
  if (!interaction.isChatInputCommand()) return;

  if (interaction.commandName === "ping") {
    await interaction.reply("Pong!");
  }
});

client.login(TOKEN);

I got the following error in repl.it:

error: Uncaught TypeError: Deno.createHttpClient is not a function
    return Deno.createHttpClient({ caCerts });
                ^
    at HttpsClientRequest._createCustomClient (https://deno.land/std@0.167.0/node/https.ts:84:17)
    at async HttpsClientRequest._final (https://deno.land/std@0.167.0/node/http.ts:136:20)

But if I run the same code in my machine it doesn't output any error but it also doesn't initialize the bot, it just freeze in the last line.

The code should initialize the bot by changing bot status to online in discord, output in console "Logged in as {bot name and tag}" and if someone write "/ping" on a discord server (where is the bot) the bot should response with "pong". In node it runs as I described.

Specs

Repl.it

Deno version: 1.28.3

My Machine

Deno version: 1.29.2
OS: Arch Linux on WSL

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working correctlyneeds investigationrequires further investigation before determining if it is an issue or notnode compat

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions