Discord Bot to automatically ban a user whose username contains a specific string.
Originally made by @Whismirk to counter the spam of bots pointing to h0nde (Twitter)
Improved by @Rikj000 to counter the spam of bots pointing to the MoniGoMani (Discord)
- If you don't have it yet, install python.
- Install
discord.py
viapip
(guide here).
-
If you don't have a dev app yet, create one on https://discord.com/developers/applications/.
-
Create a bot for your app. Save its token for later.
-
Grant privileged gateway intents to your newly made bot (just tick the options).
-
Invite the bot on your server, with appropriate permissions (namely, read and ban).
-
Then, in
autoban.py
, configure theSETTINGS
section to your needs:- You can get
user_ids
by going into your Discord settings => Advanced => Enable Developer Mode. - Then right click on a user and at the bottom of the options menu you will be able to copy the
user_id
.
# === ↓ SETTINGS ↓ ============================================================ target_strings = [ 'verification', 'your_server_name_here', 'your_moderator_name_here', 'your_moderator_name_here', 'whatever_other_words_that_need_banning', ] whitelisted_user_ids = [ 123456789123456789, # your_moderator_user_id_here 123456789123456789, # your_moderator_user_id_here ] ban_reason = 'Verification, the server name or moderator names are not allowed in the username to prevent scammers.' bot_token = 'your_bot_token_here' kick_instead_of_ban = False # set to True to kick users instead of banning # === ↑ SETTINGS ↑ ============================================================
- You can get
-
Finally, run
autoban.py
inside your terminal of choice. (The bot will only work while the script is running) -
Optional: A
Dockerfile
has been added to make running withdocker
possible 🙂