How can I create a command that gives me an effect every time I take damage?

Solution 1:

First off, regeneration is an effect which allows the player to gain health rapidly overtime with the regen speed depending on the level of its amplifier, so the effect won't just disappear after you reach full health. Can you be more specific about what you want to achieve?

But I' ll assume that you want to give players regen 3 for 2 seconds after they are hit. put the following in a repeating command block (a purple one)

execute as @a[nbt={HurtTime:10s}] run effect give @s minecraft:regeneration 2 2 false

Notice that if you put in 2 for the amplifier parameter, you get level 3 regeneration.