Minecraft command block targeting

1.13 answer:

Selector arguments are and connected, meaning @e[type=creeper,type=spider] selects everything that is both a creeper and a spider (which is nothing).

Chaining just splits up the execution, so execute as @e[type=creeper] as @e[type=spider] does something as every creeper as every spider, meaning every creeper does it as many times as there are spiders loaded.

What you want is an or connection. Minecraft isn't a proper programming language, so you need to repeat your commands for every mob type:

/execute as @e[type=creeper] run <command>
/execute as @e[type=spider] run <command>

Tip: If you have to do this multiple times or your command is very long, tag them:

/tag @e[type=creeper] add spookyScary
/tag @e[type=spider] add spookyScary
/execute as @e[tag=spookyScary] run <command>
/tag @e remove spookyScary

1.12 answer:

Selector arguments are and connected, meaning @e[type=creeper,type=spider] would select everything that is both a creeper and a spider (which is nothing). In actuality, the command just fails if you enter two of the same selector argument in 1.12.

Chaining just splits up the execution, so execute @e[type=creeper] ~ ~ ~ execute @e[type=spider] ~ ~ ~ does something as every creeper as every spider, meaning every creeper does it as many times as there are spiders loaded.

What you want is an or connection. Minecraft isn't a proper programming language, so you need to repeat your commands for every mob type:

/execute @e[type=creeper] ~ ~ ~ <command>
/execute @e[type=spider] ~ ~ ~ <command>

Tip: If you have to do this multiple times or your command is very long, tag them:

/scoreboard players tag @e[type=creeper] add spookyScary
/scoreboard players tag @e[type=spider] add spookyScary
/execute @e[tag=spookyScary] ~ ~ ~ <command>
/scoreboard players tag @e remove spookyScary