-
Hi all, I had a question on addChatPattern (doc - +PR) and would like to know how to prevent infinite loop ? a chat match a pattern, and the bot will anwer by producing a tchat that match a pattern too..
bot.addChatPattern(myEvent, /coucou/, {})
bot.on(`chat:${myEvent}`, msg => {
const botUsername = bot.username;
if (msg[0].includes(botUsername)) {
console.warn(`chat:${myEvent}: OH WAIT : dont trigger pattern on my own tchat`);
} else {
bot.chat("oh You say coucou")// including "coucou" here would cause infinite loop when trigger my own tchat is allowed
}
in advance thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
This is an issue with the regex, not an issue with mineflayer, I recommend using a page like https://regexr.com/ to test your regex patterns, also, you need capture groups for the event to return parameters. |
Beta Was this translation helpful? Give feedback.
-
The way to distinct author with addChatPatter is to use a regex and
Be warn that the regex and chat format may depend on minecraft server configuration |
Beta Was this translation helpful? Give feedback.
The way to distinct author with addChatPatter is to use a regex and
parse:true
option. This way each group of regex is forwarded to the event listener and you could simply decide what to do with each message by authorExample
Be warn that the regex and chat format may depend on minecraft server configuration