Discord.js Typescript ShardingManager 错误

问题描述 投票:0回答:0

代码

shards.ts

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

const manager = new ShardingManager('./index.ts', {
    token: process.env.TOKEN,
    totalShards: "auto"
})

manager.on("shardCreate", (shard) => {
    console.log(chalk.green.bold("[SHARDS MANAGER]"), `Launched shard ${shard.id}`)
})

manager.spawn()

错误


(node:16656) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.

(Use `node --trace-warnings ...` to show where the warning was created)

D:\Discord Bot\geubsig\shards.ts:1

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

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1176:20)
    at Module._compile (node:internal/modules/cjs/loader:1218:27)
    at Module.m._compile (D:\Discord Bot\geubsig\node_modules\ts-node\src\index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Object.require.extensions.<computed> [as .ts] (D:\Discord Bot\geubsig\node_modules\ts-node\src\index.ts:1621:12)     
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Function.Module._load (node:internal/modules/cjs/loader:958:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

我要它正常运行

typescript discord.js sharding
© www.soinside.com 2019 - 2024. All rights reserved.