Skip to content

addChatPattern : how to prevent infinite loop #3307

Closed Answered by boly38
boly38 asked this question in Q&A
Discussion options

You must be logged in to vote

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 author
Example

    addChatPattern(bot) {
        bot.addChatPattern('messageFromPlayer',
            /^<([^>]+)> (.*)$/, {"parse": true});
        bot.on('chat:messageFromPlayer', ([[user, userChat]]) => {
            console.log(`messageFromPlayer from ${user}: ${userChat}`);
        });
    }

Be warn that the regex and chat format may depend on minecraft server configuration

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@boly38
Comment options

@boly38
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by boly38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants