Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

350
Visualizações
discord.js typescript error - missing index.ts when executing 'ts-node index.ts'

I am creating a discord bot with discord.js and typescript but when I try to turn the bot on, using 'ts-node index.ts' this is the error I am given:

Error: Cannot find module 'node:events'
Require stack:
- /home/ether0p12348/RainCrown/node_modules/discord.js/src/client/BaseClient.js
- /home/ether0p12348/RainCrown/node_modules/discord.js/src/index.js
- /home/ether0p12348/RainCrown/index.ts
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue [as _resolveFilename] (/usr/local/lib/node_modules/ts-node/node_modules/@cspotcode/source-map-support/source-map-support.js:679:30)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/ether0p12348/RainCrown/node_modules/discord.js/src/client/BaseClient.js:3:22)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/ether0p12348/RainCrown/node_modules/discord.js/src/client/BaseClient.js',
    '/home/ether0p12348/RainCrown/node_modules/discord.js/src/index.js',
    '/home/ether0p12348/RainCrown/index.ts'
  ]
}

This is what I have in index.ts in the bot's root directory

const Discord = require('discord.js')

import DiscordJS, {Intents} from 'discord.js'
import dotenv from 'dotenv'
dotenv.config()

const client = new DiscordJS.Client({
    intents: [
        Intents.FLAGS.GUILDS,
        Intents.FLAGS.GUILD_MESSAGES,
    ]
})

client.on('ready', () => {
    console.log('RainCrown is ready!')
})

client.on('messageCreate', (message) => {
    if (message.content === 'ping') {
        message.reply({
            content: 'pong',
        })
    }
})

client.login(process.env.TOKEN)

all I have in ".env" is my token (edited)

my 'ls' output: index.ts node_modules package.json package-lock.json tsconfig.json

If anyone could guide me on what steps I should take to resolve this error, that would be greatly appreciated.

ps: I am using a raspberry pi with the ubuntu OS to host this bot

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You are propably not using the right node version. Try upgrading it. The newer discordjs needs atleasr v16.6. Check out this post error when requiring discordjs - cannot find module 'node:events'. I faced the same issue on 32 bit machine where i have problems installing node16, so I used the older discordjs version.

about 4 years ago · Juan Pablo Isaza Relatório

0

As Borecjeborec1 said, I just had to update my node.js to 16.6. This is the document that helped my achieve this:

https://computingforgeeks.com/how-to-install-node-js-on-ubuntu-debian/

The solution that worked for me was installing 'nvm' and installing v16 from there (solution 2 on document).

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda