Minecraft Java Edition Commands – How to Launch Commands by Clicking Words in Chat [Duplicate]

minecraft-commandsminecraft-java-edition

In the map I am currently working on, there is a part where the player can choose [Yes] / [No] from chat, where The [Yes] is in green and the [No] is in red. Then a command would be run when the player clicks on either the Yes or the No. Are there any commands that can do that?

Best Answer

You would use the /tellraw command to do this. Using the command:

/tellraw @p ["",{"text":"Yes ","color":"green","clickEvent":{"action":"run_command","value":"/tp @p x y z "}},{"text":"No","color":"red","clickEvent":{"action":"run_command","value":"/tp @p x y z "}}]

This would display text in chat "Yes No", where the Yes is green and the No is red. In the command where you see the first "/tp @p x y z" (does not need to be a tp command, of course) put whatever coordinates you want to tp the player to if they click on Yes. Do the same thing for the second "/tp @p x y z" for if they were to click on No. You are also able to add more text after or before the "Yes No".