Check if player has an item in Minecraft and if so remove it
I am creating a server where a certain item is banned. How do I get to know if a player has it in their inventory, and, if so, how can I delete all instances of it using command blocks?
You can use the https://minecraft.fandom.com/wiki/Commands/clear command.
/clear @a minecraft:flint_and_steel
@ais a https://minecraft.fandom.com/wiki/Target_selectors which selects all players. You can supply any item ID instead of
minecraft:flint_and_steel. The Minecraft wiki should tell you the ID of any item on it's page. For example, see the https://minecraft.fandom.com/wiki/Sword?so=search#ID page for all the different sword IDs.
Because you need this to execute every tick, make sure this Command Block is set to "repeating" mode. Otherwise, it will only clear the items once.