Closed urlci closed 10 years ago
I'm having the same problem, is there a workaround for this?
''' jonathan@jonathan-VirtualBox:~$ node test.js I logged in. settings { chat: 'enabled', colorsEnabled: true, viewDistance: 'far', difficulty: 2, showCape: true } current time { day: 10393, age: 306536895 }
/home/jonathan/node_modules/mineflayer/lib/plugins/chat.js:17
if (jsonMsg.translate.match(/^chat./)) {
^
TypeError: Cannot call method 'match' of undefined
at Client.
Feel free to contribute. I'd gladly accept a pull request that solved this problem cleanly.
Yeah I am interested. I'm new to Node.js so was looking for a quick solution at first. I found you can solve this problem by removing that IF statement but then chat probably wont work (don't need it yet anyway).
/home/jonathan/node_modules/mineflayer/lib/plugins/chat.js:17 if (jsonMsg.translate.match(/^chat./)) { ^ TypeError: Cannot call method 'match' of undefined
@JonnyD, This TypeError
is fixed in master (maybe I should release a version with this fix rather than wait for the chat parsing to be improved). But some non-vanilla chat formats are not supported, so it is possible that the chat is not correctly parsed and chat events not triggered.
Anyway, you can always wait for "message" events and parse the chat message on your own:
Thanks zuazo, that's very helpful! :+1:
@zuazo there's a problem with that code at line 56: message is not a variable.
Fix it by replacing message with jsonMsg.
Is there any support for messages sent by the server?
@zuazo there's a problem with that code at line 56: message is not a variable.
Thanks for testing :smile: I think I fixed it in master.
Is there any support for messages sent by the server?
AFAIK, you should be able to read them listening to "message" events. Other than that, are not supported.
Thanks! Actually server messages do work.
How could I change these regular expressions to support Herochat:
A spoken message with Herochat should be "Player: Hello". I got that work by removing the surrounding '<' and '>'. A whisper with Herochat should be "From Player: Hello". I added 'From' into the regular expression but it still matches the first one?
if (match = legalContent.match(/^(?:.+? )?(.+?) (.*)$/)) {
// spoken chat
username = match[1];
content = match[2];
bot.emit('chat', username, content, message);
} else if (match = legalContent.match(/^(From ?:.+? )?(.+?) (.*)$/)) {
// whispered chat
username = match[1];
content = match[2];
bot.emit('whisper', username, content, message);
}
I think you could test the whisper regex before the normal chat regex. Something like the following:
if (match = legalContent.match(/^From (?:.+? )?(.+?) (.*)$/)) {
// whispered chat
username = match[1];
content = match[2];
bot.emit('whisper', username, content, message);
} else if (match = legalContent.match(/^(?:.+? )?(.+?) (.*)$/)) {
// spoken chat
username = match[1];
content = match[2];
bot.emit('chat', username, content, message);
}
Will be handled by https://github.com/andrewrk/mineflayer/issues/175 Full support will be available in 1.7
Hello.
I found this project by a chance and love it. I've been working on it and trying to understand how it works for few days so I can build my own bot. However I am having few issues with non-vanilla server which doesn't occur on vanilla servers. At first I was not even able to stay connected to the server because of the chat.js plugin just like this issue https://github.com/superjoe30/mineflayer/issues/159. I guess bot were getting disconnected due to server's welcome message or something else. Luckily I made a change on the line of chat.js plugin as zuazo stated; https://github.com/superjoe30/mineflayer/commit/fe2a7f1. Now I can stay connected to the server, but bot does not react anything depending bot.on(chat) event. But the weird thing is it works completely as expected on my vanilla server. My guess about on this issue is modified player names. As you know on vanilla servers when a player sends a global message, server prints it on chat GUI as;
< PlayerA > Hello world.
However on the sever which I am trying to make my bot work, it works this way;
PlayerA : Hello world.
So I assume characters (<,>) causes this problem. I have no idea if this can be modified or username type is changeable.
I hope you could tell me a simple solution for me. Thank you.