PrismarineJS / mineflayer

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

"addChatPattern" not existing in mineflayer@4.9 but has not been stated that it has been removed #3245

Closed Myzumi closed 10 months ago

Myzumi commented 10 months ago

Versions

Detailed description of a problem

A clear and concise description of what the problem is, with as much context as possible. What are you building? What problem are you trying to solve?

bot.addChatPattern does not existis anymore when upgrading to mineflayer@4.9 from 4.8.1 It has been tested with the latest version and with 4.10, 4.9, 4.8.1/4.8

What did you try yet?

Downgrading to find exact version that changes this. This problem also persist in all versions above 4.9

Your current code

  const bot = await minecraft.createBot({
    auth: 'microsoft',
    username: process.env.GuildBotEmail,
    accessToken: process.env.GuildBotToken,
    //password: process.env.GuildBotPassword,
    chat: 'enabled',
    viewDistance: 1,
    version: "1.8.9",
    host: "hypixel.net",
  })

  bot.addChatPattern("in_limbo", /You were spawned in Limbo./)
  bot.addChatPattern("guild_chat", regex_guildchat, {parse: true})
  bot.addChatPattern("guild_join", /^Guild > ([\w\d]{2,17}).*? joined.*$/i, {parse: true})
  bot.addChatPattern("guild_left", /^Guild > ([\w\d]{2,17}).*? left.*$/i, {parse: true})
  bot.addChatPattern("guild_member_left", /^(\[.*?\])*.*? ([\w\d]{2,17}).*? left the Guild!*$/i, {parse: true})
  bot.addChatPattern("guild_member_join", /^(\[.*?\])*.*? ([\w\d]{2,17}).*? joined the Guild!*$/i, {parse: true})

most of the unrelated code has been removed and only relevant code is shown.

Expected behavior

A clear and concise description of what you expected to happen. That bot.addChatPattern exists on the bot property in the version 4.9 and above as changelog does not state that it had been removed.

Additional context

Add any other context about the problem here. image

extremeheat commented 10 months ago

This is because you are not waiting for the correct event. mineflayer requires you to wait for events like spawn before those functions become available.

Myzumi commented 10 months ago

This is because you are not waiting for the correct event. mineflayer requires you to wait for events like spawn before those functions become available.

Worked before without waiting for that event, so it was defently not mentioned in the changelog

extremeheat commented 10 months ago

It should not have been working if it did, as createBot() is not a synchronous call, it works asynchronously. As in the examples, all the mineflayer bot API methods (like this one) have to be called after the appropriate event, like connection to server, etc. Should be made clear in the API if not already. Feel free to do a PR to add that note to the api.md