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

Convert message event to function #724

Closed The-Box1 closed 5 years ago

The-Box1 commented 6 years ago

Before you ask yes I have checked other issues. The chat event isn't working but the message on is. Although is there a way to use it as a function and get the username from it? Also not just the raw text?

plexigras commented 6 years ago

we should consider adding a "is bot.on('chat', ...) not working?" section to the issue template.

what is the output of bot.on('message', m => console.log(m.toString()))?

roblabla commented 6 years ago

What does "convert message event to function" even means?

The "chat" event attempts parsing the message to find the username from the raw text. It does this using a RegEx. By default, that regex works for the default chat stuff, but it doesn't work on server that use a plugin to customize the chat output. You'll need to customize the regex for it to work: https://github.com/PrismarineJS/mineflayer/blob/master/examples/chatAddPattern.js#L31

otherwise, you can parse the raw message from the "message" event directly.

rom1504 commented 5 years ago

Done