1

I'm trying to configure the shard system in my bot, developed in TypeScript, however, when I configure the main file, discord.js itself does not recognize the file written in ts.

Here's the error:

TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".ts" for C:\Users\.\Documents\Programação\Discord\Pessoal\Tom5\Tom5#v6\src\bot.ts

The launcher.ts file (responsible for creating the shards):

import chalk from "chalk";
import { ShardingManager } from "discord.js";

export class ShardsManager extends ShardingManager {
    constructor() {
        super(
            "src/bot.ts",
            {
                token: "", //I've been putting the bot's token here
                respawn: true,
                totalShards: "auto",
            }
        )

        this.on("shardCreate", (shard) => {
            console.log(
                chalk.bold.green(
                    `[SHARD - ${shard.id + 1}]`
                ),
                "Criada"
            )
        })

        this.spawn()
    }
}


new ShardsManager()

The main file (bot.ts):

import chalk from "chalk";
import Tom5 from "./classes/Tom5";
import * as dotenv from "dotenv"
dotenv.config()

process.on('unhandledRejection', (reason, p) => {
    console.log(
        chalk.bold.red(
            "[SCRIPT REJEITADO]\n"
        ),
        reason
    )
});

process.on("uncaughtException", (err, origin) => {
    console.log(
        chalk.bold.red(
            "[ERRO CAPTURADO]\n"
        ),
        err
    )
})

process.on('uncaughtExceptionMonitor', (err, origin) => {
    console.log(
        chalk.bold.red(
            "[SCRIPT BLOQUEADO]\n"
        ),
        err
    )
});

await new Tom5().init()

Best regards, TomG

I tried to rename the file to bot.js, however, it caused multiples unnecessary errors, especially importing typescript files

TomG
  • 19
  • 4
  • Does this answer your question? [Can't run my Node.js Typescript project TypeError \[ERR\_UNKNOWN\_FILE\_EXTENSION\]: Unknown file extension ".ts" for /app/src/App.ts](https://stackoverflow.com/questions/62096269/cant-run-my-node-js-typescript-project-typeerror-err-unknown-file-extension) – Zsolt Meszaros May 17 '23 at 21:00
  • @ZsoltMeszaros No, it is all like they suggested. – TomG May 17 '23 at 22:21
  • Are you using ts-node? – GodderE2D May 19 '23 at 02:23
  • @GodderE2D yes. Is it causing this? – TomG May 19 '23 at 13:49

0 Answers0