As you can see, I was trying to write a command. This command was supposed to give me a diamond (for example) by pressing the lever if there is any entity in the loaded chunks other than raiders. But even in their presence, at the touch of a lever, I get a diamond. Am I doing something wrong?
Perhaps you want
unless entity @e[[type=#raiders]|#raiders]
? Currently it's checking if there is any non-raider entity, and it's finding you (the player, a non-raider entity) every time