You’ll want to use the UserDestroyer
to delete a user properly. Something like this should work:
UserDestroyer.new(Discourse.system_user).destroy(User.find_by_username_or_email("ex@example.com"), delete_posts: false)
That will have the system user delete the user with the email ex@example.com
. You can also provide a username instead of email.
If you want the logs to show who deleted the user, replace Discourse.system_user
with User.find_by_username_or_email("admin@example.com")
where admin@example.com
is the email of a site admin.