Can i use the /testfor command to check for certain words in chat?

Can i use the /testfor command to check for certain words in chat? - Stylish adult female using smartphone on street

I want to be able to detect if a certain word in chat is said like:

Console: Please say yes to be teleported or no to remain
Player1: yes
Player1 teleported to [insert random coordinates here]

Something that would monitor the chat for a certain word.



Best Answer

Unfortunately there is simply no way, currently, to test for what players say in chat.


There is however an alternative which is quite similar; using /tellraw along with the new (1.8 snapshots only so far) /trigger command. This would allow you to create a message in chat that looks something like this:

Would you like to be teleported? [Yes]

And would actually work when you clicked the [Yes] button.


First you'll need to create an objective (lets say, Objective1) with type "trigger". Then, you'll need to use /scoreboard players enable Player1 Objective1 to allow Player1 to use /trigger Objective1. You'll need to do this each time you ask the player if they want to teleport.

Then, to display the actual clickable message, run something like this in a command block:

/tellraw Player1 {"text":"Do you wish to be teleported? ","extra":[{"text":"[Yes]","clickEvent":{"action":"run_command","value":"/trigger Objective1 set 1"}}]}

This sets their Objective1 score to 1, and from there you can simply do something like /tp @a[score_Objective1_min=1] Coordinates.


Here's a site that's quite useful for generating tellraw commands; there is a lot you can do with them but the syntax can initially be very confusing: http://ezekielelin.com/minecraft/tellraw/




Pictures about "Can i use the /testfor command to check for certain words in chat?"

Can i use the /testfor command to check for certain words in chat? - Young troubled woman using laptop at home
Can i use the /testfor command to check for certain words in chat? - Serious ethnic young woman using laptop at home
Can i use the /testfor command to check for certain words in chat? - Crop aged redhead female in eyeglasses using contemporary mobile phone while surfing internet in soft focus



How do you test chat in Minecraft?

One way to monitor chat is to have "choose-your-adventure" format, ie made with /tellraw commands that have a click event which causes the player to choose what they say, and control functioal reactions by setting clickEvent areas to place redstone blocks in a possibly remote system.

How do you test a specific item in Minecraft?

You can test for a certain target in the game using the /testfor command in Minecraft. TIP: Starting in Minecraft Java Edition (PC/Mac) 1.13, the /testfor command was removed from the Java Edition version of the game. Let's explore how to use this cheat (game command).

What does the Testfor command do?

The /testfor command became obsolete in Minecraft 1.13, and has been replaced by the /execute command*. It will do the same as typing /testfor @e {SelectedItem:{id:"<item>"}} and then putting a comparator to the command block with the command, and then running the command which you wanna run.



Minecraft Redstone Tutorial | How to use testfor commands in MCPE!




More answers regarding can i use the /testfor command to check for certain words in chat?

Answer 2

Even simpler than the above, again made with the very useful tool ezekielelin's tellraw generator If you put this into a command block all you need to do is change the [target player] and x, y, z and add/ remove the x and y rotation

tellraw @a {"text":"","extra":[{"text":"Do you want to be teleported?"},{"text":"[Yes]","clickEvent":{"action":"run_command","value":"/tp [target player] <x> <y> <z> [<y-rot> <x-rot>]"}}]}

Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Andrea Piacquadio, Andrea Piacquadio, Andrea Piacquadio, Anna Shvets