javascript Mineflayer.js机器人程序在Bot.chat()上崩溃

ffx8fchx  于 2022-12-25  发布在  Java
关注(0)|答案(1)|浏览(179)

bot.chat()是不工作,我尝试使用等待和不使用它,它说不能读取未定义的属性.这里是我的代码和错误日志.这是库:https://github.com/PrismarineJS/mineflayer,它使用的是Minecraft协议

mineflayer = require('mineflayer');
let requirements = {
    'host':'mc.ip.net',
    'port':'88888',
    'version':'1.19.2'
};

class MCBot{
    // Constructor
    constructor(username){
        this.username = username;
        this.host = requirements['host'];
        this.port = requirements['port'];
        this.version = requirements['version'];

        this.initBot()
    };
    // Init Bot Instance
    initBot(){
        this.bot = mineflayer.createBot({
            'username': this.username,
            'host': this.host,
            'port': this.port,
            'version': this.version
        });
        this.initEvents()
    }
    // Init Bot Events
    initEvents(){
        // Login Event
        this.bot.on('login', ()=>{
            let botSocket = this.bot._client.socket;
            console.log(`[${this.username}] Logged in to ${botSocket.server ? botSocket.server : botSocket.host}`);
        });
        // Disconnect Event
        this.bot.on('end', ()=>{
            console.log(`[${this.username}] Disconnected`);
            // Reconnection Attempt
            setTimeout(()=> this.initBot, 2000);
        });
        // Error Event
        this.bot.on('error', (err)=>{
            if(err.code==='ECONNREFUSED'){
                console.log(`[${this.username}] Failed to Reconnect to ${err.address}:${err.port}`);
            }else{
                console.log(`[${this.username}] Unhandled Error: ${err}`);
            }
        });
        // Spawn Event
        this.bot.on('spawn', async ()=>{
            console.log(`[${this.username}]  Spawned in`);
            await this.bot.waitForTicks(0)
            this.bot.chat(`${this.username}'s Ready!`);
            /*
            await this.bot.waitForTicks(60);
            this.bot.chat("Goodbye!");
            this.bot.quit();
            */
        });
    }
}
new MCBot("Bob")
// let bots = ["Bob"]
// for(var i = 0; i<bots.length; i++){
//     bots.push(new MCBot(bots[i]))
//     console.log("Bot added")
// }

这是我得到的错误,它似乎有一些问题的长度,但我找不到任何东西

[Bob] Logged in to undefined
[Bob]  Spawned in
TypeError: Serialization error for play.toServer : SizeOf error for undefined : Cannot read properties of undefined (reading 'length')
    at Object.previousMessages (eval at compile (C:\Users\xianc\Desktop\CHRIS\Minecraft\Bots\node_modules\protodef\src\compiler.js:258:12), <anonymous>:175:37)
    at Object.packet_chat_message (eval at compile (C:\Users\xianc\Desktop\CHRIS\Minecraft\Bots\node_modules\protodef\src\compiler.js:258:12), <anonymous>:599:37)
    at eval (eval at compile (C:\Users\xianc\Desktop\CHRIS\Minecraft\Bots\node_modules\protodef\src\compiler.js:258:12), <anonymous>:1222:64)
    at packet (eval at compile (C:\Users\xianc\Desktop\CHRIS\Minecraft\Bots\node_modules\protodef\src\compiler.js:258:12), <anonymous>:1270:9)
    at CompiledProtodef.sizeOf (C:\Users\xianc\Desktop\CHRIS\Minecraft\Bots\node_modules\protodef\src\compiler.js:89:14)
    at e.message (C:\Users\xianc\Desktop\CHRIS\Minecraft\Bots\node_modules\protodef\src\compiler.js:96:40)
    at tryCatch (C:\Users\xianc\Desktop\CHRIS\Minecraft\Bots\node_modules\protodef\src\utils.js:50:16)
    at CompiledProtodef.createPacketBuffer (C:\Users\xianc\Desktop\CHRIS\Minecraft\Bots\node_modules\protodef\src\compiler.js:96:20)
    at Serializer.createPacketBuffer (C:\Users\xianc\Desktop\CHRIS\Minecraft\Bots\node_modules\protodef\src\serializer.js:12:23)
    at Serializer._transform (C:\Users\xianc\Desktop\CHRIS\Minecraft\Bots\node_modules\protodef\src\serializer.js:18:18) {
  field: 'play.toServer'
}
[Bob] Unhandled Error: TypeError: Serialization error for play.toServer : SizeOf error for undefined : Cannot read properties of undefined (reading 'length')
[Bob] Disconnected

我尝试使用await和不使用它,但它做同样的事情

mfuanj7w

mfuanj7w1#

正如您可以从官方存储库中读取的:https://github.com/PrismarineJS/mineflayer
尚不支持1.19以后的版本
主要问题是由微软在最新更新中制作的聊天签名系统引起的。
所以我们必须等到mineflayer和它的库更新!

相关问题