Is there any way to check if a player drank a specific potion?

I tried something like this: scoreboard objectives add potion minecraft.used:minecraft.potion 0 But that went up every time I drank any type of potion. And this isn't a command: scoreboard objectives add potion potion{CustomPotionEffects:[{Id:1b,Amplifier:0b,Duration:2400}]} 0 So I would like some help with this.


Solution 1:

You can use the minecraft.used:minecraft.potion criteria in combination with a tag to do this. The criteria would be used to detect when the player drinks a potion and the tag would serve as an indicator that the player is holding the correct potion.

I put together a simple example of this concept. Just create this scoreboard objective:

/scoreboard objectives add potion minecraft.used:minecraft.potion

and paste the following commands into a chain of command blocks (repeating command block and some chain command blocks attached to it).

/tag @a[nbt={SelectedItem:{id:"minecraft:potion",tag:{CustomPotionEffects:[{Id:1b,Amplifier:0b,Duration:2400}]}}},tag=!correctPotion] add correctPotion
/execute as @a[scores={potion=1..},tag=correctPotion] run say drank healing potion
/tag @a[nbt=!{SelectedItem:{id:"minecraft:potion",tag:{CustomPotionEffects:[{Id:1b,Amplifier:0b,Duration:2400}]}}},tag=correctPotion] remove correctPotion
/scoreboard players reset @a[scores={potion=1..}] potion

Just replace the NBT data in SelectedItem with the data your potion has. I used the example you provided in your post.