我的目标是创建一个地雷飞行器的机器人用户。我安装了node.js,并从终端安装了地雷飞行器,然后创建了一个变量,即require('mineflayer')。然后我用
const mineflayer=require('mineflayer');
const bot=mineflayer.createBot({
host:'minehut.gg', //only for test purposes
username: 'MyUserName',
password: 'myPWD'
});
const plankRecipe = bot.recipesFor(5)[0];但是,在该片段的最后一行中,它抛出以下内容:TypeError: bot.recipesFor is not a function。它为什么要这样做,我如何让它认识到它是一个函数?到目前为止,我唯一的理论是,它没有连接,只是没有告诉我它不能正确地实现机器人的目标。
谢谢!
编辑: WebStorm调试器说bot是一个EventEmitter对象,而不是预期的Bot对象。这个有用吗?
发布于 2021-05-31 03:24:46
在布雷者中,机器人在创建时没有任何方法(除了EventEmitter方法)。当您登录时,机器人会得到它的方法。
这是有道理的,因为如果机器人没有连接到游戏中,它们就不能做很多事情。甚至制作食谱也是服务器端的。
这将是正确的代码:
const mineflayer = require("mineflayer"),
bot = mineflayer.createBot({
host: "example.com",
username: "my_username",
password: "my_password"
});
bot.once("login", () => {
const plankRecipe = bot.recipesFor(5)[0];
});看看他们的一个示例。
不幸的是,mineflayer的API文档并不容易实现这一点。
错误TypeError: bot.recipesFor is not a function的意思就是:您试图调用的“函数”不是一个函数,这可能意味着它不存在,或者是一个非函数的变量。
发布于 2021-05-30 20:19:55
我已经检查了正式文档,recipesFor方法接受了4项论证
您可以查看文档这里
https://stackoverflow.com/questions/67764944
复制相似问题