PrismarineJS / mineflayer

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

bot.chat doesn't work anymore #2988

Closed SonicandTailsCD closed 1 year ago

SonicandTailsCD commented 1 year ago

Versions

Detailed description of a problem

A clear and concise description of what the problem is, with as much context as possible. The bot was joining fine and was working with bot.chat() correctly. Out of nowhere, the bot stops working and throws me off with this error: /Users/adm/Desktop/Bot/node_modules/mineflayer/lib/plugins/chat.js:177 bot._client.chat(smallMsg) ^

TypeError: bot._client.chat is not a function at /Users/adm/Desktop/Bot/node_modules/mineflayer/lib/plugins/chat.js:177:21 at Array.forEach () at chatWithHeader (/Users/adm/Desktop/Bot/node_modules/mineflayer/lib/plugins/chat.js:171:25) at EventEmitter.bot.chat (/Users/adm/Desktop/Bot/node_modules/mineflayer/lib/plugins/chat.js:207:5) at Object. (/Users/adm/Desktop/Bot/bot2.js:27:5) at Module._compile (node:internal/modules/cjs/loader:1099:14) at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10) at Module.load (node:internal/modules/cjs/loader:975:32) at Function.Module._load (node:internal/modules/cjs/loader:822:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)

Node.js v17.9.1 What are you building? Simple bot that uses one plugin to load its skin: SkinRestorer What problem are you trying to solve? I need that bot to join

What did you try yet?

Did you try any method from the API?No, I don't even know what that is. Did you try any example? yes Any error from those? yes

Your current code


// Here I tell node.js mineflayer and a few other plugins are required to load
const mineflayer = require('mineflayer')

// Here, we set up the server connection (in this case, my skin plugin server)
const bot = mineflayer.createBot({
    host: 'SonicJavaBots.aternos.me',
    port: '37867',
    username: "SonicandTailsCDb",
    version: '1.18.2'
})
// I'm online right now, join up if you want

// And now, we work on the AI here!
// Here's all of the functions:
// One note tho: All functions are placeholders.
function onPhysicsTick () {}
function onSpawn () {
    bot.chat("Hey! I'm working properly :D")
}

// I need to set physicsTick because I want the AI to target me.
bot.on('physicsTick', onPhysicsTick)

// Next, I'm gonna set spawn actions.
bot.on('spawn', onSpawn)

// Set skin, of course!
bot.chat("/skin set SonicandTailsCDb robot1_stevetest")

Expected behavior

A clear and concise description of what you expected to happen. The bot joining and having the skin

Additional context

Add any other context about the problem here. NO. Thanks :)

ghost commented 1 year ago

You used bot.chat before logging in to the server. Move bot.chat("/skin set SonicandTailsCDb robot1_stevetest") inside onSpawn

SonicandTailsCD commented 1 year ago

Of course I did. There's a bug with the plugin that I use that respawns you after applying the skin. Or maybe it's intentional, idk! After the bot respawns, it does it again. And it loops. What should I do?

On Mar 23, 2023, at 14:28, 678435021 @.***> wrote:



You used bot.chat before logging in to the server. Move bot.chat("/skin set SonicandTailsCDb robot1_stevetest") inside onSpawn

— Reply to this email directly, view it on GitHubhttps://github.com/PrismarineJS/mineflayer/issues/2988#issuecomment-1481937315, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ATDUSLDTBC7H74S3AWMBQQTW5SW6TANCNFSM6AAAAAAWFVZHCM. You are receiving this because you authored the thread.Message ID: @.***>

SonicandTailsCD commented 1 year ago

Oh and me moving that line to onSpawn won't work for me. Anything else I can do?

ghost commented 1 year ago

There's a bug with the plugin that I use that respawns you after applying the skin.

I think it does that to refresh the skin and work properly. I think it's intentional

After the bot respawns, it does it again. And it loops. What should I do?

bot.on('spawn', onSpawn) will run the onSpawn function every time the spawn event gets emitted, not just once, making it loop. Change bot.on('spawn', onSpawn) to bot.once('spawn', onSpawn) to make it trigger only once

ghost commented 1 year ago

Oh and me moving that line to onSpawn won't work for me. Anything else I can do?

It worked for me when I moved it there

SonicandTailsCD commented 1 year ago

Alright. I'm gonna try that… don't close this yet, maybe I still have some other issue. Thanks in advance :)

SonicandTailsCD commented 1 year ago

This worked, the bot spawned correctly. Thanks :)