【发布时间】:2020-11-30 11:05:27
【问题描述】:
所以我一直在尝试为我的世界中的机器人编写代码,但是在执行命令时:
node index.js
然后发生这种情况:
internal/modules/cjs/loader.js:968
throw err;
^
Error: Cannot find module 'C:\Users\monst\Downloads\Serverchat\index.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
at Function.Module._load (internal/modules/cjs/loader.js:841:27)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
at internal/main/run_main_module.js:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
这是代码:
const Discord = require("discord.js");
const mineflayer = require("mineflayer");
const client = new Discord.Client();
let prefix = ".";
let bot = mineflayer.createBot({
version: "1.12.2",
host: "example.org",
username: "email",
password: "password",
})
client.on("ready", async => {
console.log("Bot Online")
})
bot.on("login", async => {
console.log("Ingame Bot Online")
bot.chat("Online!")
})
bot.on("message", message => {
let channel = client.channels.cache.get(742454971450261557)
if (!channel) return;
channel.send(`${message}`)
})
client.login("token")
如果有人能帮忙,那对我来说就意味着整个世界!
【问题讨论】:
-
A) 这个文件叫什么? B) 你是如何运行它的?
-
还值得注意的是,像
742454971450261557这样的数字太大而无法正常表示,并且可能会被四舍五入。你需要像742454971450261557n一样使用BigInt。 -
@tadman 这个文件叫做 index.js。
-
@tadman 哦,这些大数字被用作不和谐频道的 id。如果它没有被使用,并且如果我在最后放置一个 n,它就不起作用。
-
@TobiasNielsen Discord.js 期望您将 ID 作为字符串而不是数字提供,这正是 tadman 上面解释的原因。
标签: node.js discord.js