所以我一直在尝试为我的世界中的机器人编写代码,但是在执行命令时:
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")
如果有人可以帮助,那对我来说意味着世界!
答案 0 :(得分:1)
第一件事:
您的漫游器令牌就像一个用户名和密码一样。任何获得它的人都可以采取任何行动,就好像他们是您的机器人一样,包括进行对话并删除类似的渠道和内容。我已通过编辑从您的问题中删除了该文件,但强烈建议您转到Discord门户并立即将其重置。
此外,主要问题:
错误已明确写入。 Error: Cannot find module 'C:\Users\monst\Downloads\Serverchat\index.js'
。这意味着该文件夹中没有名为index.js
的文件。看到它也是一个不和谐的机器人,也许您的意思是node bot.js
?否则,您的代码可能在另一个工作目录中。使用cd
在命令提示符下将您的工作目录更改为您的机器人代码和node_modules
所在的位置。
另一件事:JavaScript不能将Snowflakes表示为原始数字-精度损失将导致最后几个数字略有变化。因此,discord库(包括discord.js)要求您将ID作为字符串传递,如下所示:
let channel = client.channels.cache.get("742454971450261557")