PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
4.96k stars 904 forks source link

chat() didn't work #2924

Closed XingYuan55 closed 1 year ago

XingYuan55 commented 1 year ago

When I use the bot.chat("123") function and pass in arguments, it reports an error saying: bot._client.chat() is not a function. But when I don't pass in any arguments, it asks for them again. I don't know what's going on, but it's been bugging me for a long time. How can I get chat to work I'm having problems doing this in python as well as this. Error message:

d:\py_proj\test\node_modules\mineflayer\lib\plugins\chat.js:177
        bot._client.chat(smallMsg)
                    ^

TypeError: bot._client.chat is not a function
    at d:\py_proj\test\node_modules\mineflayer\lib\plugins\chat.js:177:21
    at Array.forEach (<anonymous>)
    at chatWithHeader (d:\py_proj\test\node_modules\mineflayer\lib\plugins\chat.js:171:25)      
    at EventEmitter.bot.chat (d:\py_proj\test\node_modules\mineflayer\lib\plugins\chat.js:207:5)
    at Object.<anonymous> (d:\py_proj\test\b.js:12:5)
    at Module._compile (node:internal/modules/cjs/loader:1165:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1219:10)
    at Module.load (node:internal/modules/cjs/loader:1043:32)
    at Function.Module._load (node:internal/modules/cjs/loader:878:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)  

Source code: (I made a simple test program because it's my first time using it)

const mineflayers = require("mineflayer")

const bot = mineflayers.createBot({
    "host": '***', 
    "username": '**', 
    "port": ****,               
    "version": "1.16.5",  
})
bot.chat("a")

Also, may I ask, does mineflayer support offline login for bots?

frej4189 commented 1 year ago

Update your node-minecraft-protocol

XingYuan55 commented 1 year ago

Update your node-minecraft-protocol

How can I update it?

amoraschi commented 1 year ago

How can I update it?

npm update node-minecraft-protocol

Also, wait for the bot to spawn with the "spawn" event

extremeheat commented 1 year ago

Update dependencies with

npm update --depth 9999

This will update all the sub dependencies and make sure everything is in sync, as this is how it will appear in fresh install / our CI.

XingYuan55 commented 1 year ago

Ok, I'll try it, and continue to follow the post if necessary

XingYuan55 commented 1 year ago

Update dependencies with

npm update --depth 9999

This will update all the sub dependencies and make sure everything is in sync, as this is how it will appear in fresh install / our CI.

Also, may I ask, does mineflayer support offline login for bots?

XingYuan55 commented 1 year ago

But, annoyingly, after I update it, it still reports this error

extremeheat commented 1 year ago

You did not update it correctly then. Try the command above again or install to a new folder

XingYuan55 commented 1 year ago

您当时没有正确更新它。再次尝试上述命令或安装到新文件夹

Let me try

XingYuan55 commented 1 year ago

Oh no! After I moved to the new folder and re-executed the install command with the update command, I ran the code and it still reported the same error. I don't know if it's a problem with Node.js or my computer 😟

extremeheat commented 1 year ago

Likely you installed mineflayer globally, or there is another node_module folder taking precedence. You can try on a different machine or use an environment like Gitpod.

XingYuan55 commented 1 year ago

可能是您全局安装了 mineflayer,或者有另一个优先node_module文件夹。您可以在其他计算机上尝试或使用 Gitpod 等环境。

Yes, you are right. I had installed mineflayer globally. so, I uninstall the global one and it will work? Let me try it.

XingYuan55 commented 1 year ago

I don't have any other node_modules folder, and I uninstalled the global installation of mineflayer, but the error is still there.

Zn10plays commented 1 year ago
  1. As previously stated the reason you are unable to use .chat() is because you have to wait for the bot to spawn before firing the event. example listed bellow.

bot.once('spawn', () => { bot.chat("Hello!") })

  1. If this issue is complete, please close it.
XingYuan55 commented 1 year ago

哦!谢谢你!成功了!!!! OH!! Thank You!!!! It's OK!