Minecraft – /tellraw with teleporting

minecraft-commandsminecraft-java-edition

Is there a way to use the "selector" command with tellraw so that it displays a players name in chat and THEN teleports that player to a location? I know how to do each separately but I don't know how to do both using the previously selected player who was chosen to be teleported. Please help.

Best Answer

To clarify Daniel's answer, you can assign a tag to a player when they click on a command in the chat using the following command in a tellraw command:

/scoreboard players tag @p add command_clicked

Then, in a repeating command block chain, you can execute the following 3 commands in order:

/say @a[tag=command_clicked]
/tp @a[tag=command_clicked] <destination>
/scoreboard players tag @a remove command_clicked