Would it be possible to make a command block that has commands set when placed?

Some backstory. I wanted to make a command block that had a simple command when placed: Kill all users and set block to air to stop the trigger.
However, I had no idea how to make it so a command block had commands already input on place.
Is this possible? (Version 1.16.5)


You can do this from scratch with /setblock:

setblock 12 23 34 minecraft:command_block[]{Command:"…"}

Your command goes inside those quotation marks right there.

If you are looking to get this command block as an inventory item, use BlockEntityTag like so:

give @p minecraft:command_block{BlockEntityTag:{Command:"…"}}

Beware as you will need to escape quotation marks in your inner command, which can lead to messes like these!


So make the command block with the command to make it so it kills when placed and set to always active then I think it hold shift and click the block and the code should stay in the command block.