Is there a way to only give a player in a certain distance from a command block an effect if they don’t have the effect in 1.19.2?

I’m having the issue where it just spams the effect making it kinda useless and it fills the chat with a bunch of messages that the player was given the effect.

1 Answer 1


To apply an effect to a player only if they don't already have that effect, you can use a combination of the execute and effect commands.

Here's how:

Try this command (make sure the command block is set to "Repeat" and "Always Active"):

execute as @a[distance=..5] unless entity @s[nbt={ActiveEffects:[{Id:<effect_id>}]}] run effect give @s <effect> <duration> <amplifier> true

@a[distance=..5]: targets all players within a radius of 5 blocks (you can change the distance).

unless entity @s[nbt={ActiveEffects:[{Id:<effect_id>}]}]: checks if the player doesn't have any effect.

effect give @s <effect> <duration> <amplifier> true: gives the effect to the player. The true parameter hides the particle effects.

For exp, if you want to give the player Speed effect (effect ID 1) for 10 seconds with an amplifier of 1:

execute as @a[distance=..5] unless entity @s[nbt={ActiveEffects:[{Id:1}]}] run effect give @s minecraft:speed 10 1 true

And to prevent the chat from being spammed, the true at the end of the effect command ensures that the effect application is silent.

Let me know how it works.

  • 1
    Thank you so much this is amazing Commented Jun 5 at 13:53
  • Great to hear, it works for you Royce, can you accept the answer? If you still have any query, just ask me.
    – Miles G.
    Commented Jun 5 at 14:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .