How to make bats giving poison effect to nearby players?

Bats don't do anything, and I'm thinking of making a datapack, so that when a bat gets close to a player, it will "bite" them, giving them a poison effect.

How would I do this?


If you want to make them constantly give poison to nearby players you can do this:

/execute at @e[type=minecraft:bat] run effect give @a[distance=..2] minecraft:poison 1 1 true