As others said you can’t prevent them completely. Only partially. You do it four steps:
Make it unattractive for bots.
Prevent them from joining.
Prevent them from posting/commenting.
Detect them and kick them out.
The sad part is that, if you go too hard with bot eradication, it’ll eventually inconvenience real people too. (Cue to Captcha. That shit is great against bots, but it’s cancer if you’re a human.) Or it’ll be laborious/expensive and not scale well. (Cue to “why do you want to join our instance?”).