Skip to content

Instantly share code, notes, and snippets.

@vivekjoshy
Last active May 2, 2024 12:15
Show Gist options
  • Save vivekjoshy/dda3dc99c09e2c6430b09c9ae23b646b to your computer and use it in GitHub Desktop.
Save vivekjoshy/dda3dc99c09e2c6430b09c9ae23b646b to your computer and use it in GitHub Desktop.
Script to ban members of a discord servers.
#!/usr/bin/python
"""
# WARNING!
# DO not use this script for malicious purposes!
# Author: daegontaven - taven#0001
# License: Public Domain
# README
# I have resigned from using discord indefinitely to pursue schoolwork.
# As such I will not be maintaining this script anymore.
# How to Install
1 - Download Python 3.7 or 3.6 : https://www.python.org/downloads/
2 - Run this command : python3 -m pip install discord.py
3 - Run this command : python3 discord-ban-bot.py
4 - Invite bot to the servers you want to ban members from.
5 - Wait until banning is done. Don't close the terminal. This may take a while.
"""
import discord
TOKEN = "" # Put your Bot token here
SKIP_BOTS = False
client = discord.Client()
@client.event
async def on_ready():
print('Logged in!')
for member in client.get_all_members():
if member.bot and SKIP_BOTS:
continue
await member.ban(reason="Banned by BanBot", delete_message_days=7)
print(f"Banned {member.display_name}!")
print("Banning is complete!")
client.run(TOKEN)
@bvfvf
Copy link

bvfvf commented Jul 13, 2019

not working for me

@vivekjoshy
Copy link
Author

@bvfvf Please be a bit more specific. How do I reproduce what you're facing?

@cozyscripts
Copy link

Nice script! I understand what you're doing here but I'm making my own bot right now and I wanted to use this script as a reference. Do you know how I could specify a member to ban and then ban them? I'm struggling with the documentation

@SALADSWIPER
Copy link

Sorry, I tried adding your discord but it did not work. I do not understand why it is not working! I pasted the code into Glitch.com, and added the package of Python. I invited it to a server and it did not ban anyone

@SALADSWIPER
Copy link

Maybe you can add me on discord and we can test it together if you would like. imxaoeva#3207

@vivekjoshy
Copy link
Author

@SALADSWIPER I tried adding you but it did not work (says your username does not exist). Anyways I'm not a user of glitch. If you want a fix, please give me the specific error and instructions to reproduce it. Thank you!

@drdestroy
Copy link

I need some help, user: drdestroy#6906

@E40e
Copy link

E40e commented Nov 14, 2020

I followed all the steps, but I keep getting this error
C:\Users\Faisal\Desktop>discord-ban-bot.py
Logged in!
Ignoring exception in on_ready
Traceback (most recent call last):
File "C:\Users\Faisal\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\client.py", line 333, in _run_event
await coro(*args, **kwargs)
File "C:\Users\Faisal\Desktop\discord-ban-bot.py", line 33, in on_ready
await member.ban(reason="Banned by BanBot", delete_message_days=7)
File "C:\Users\Faisal\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\member.py", line 498, in ban
await self.guild.ban(self, **kwargs)
File "C:\Users\Faisal\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\guild.py", line 1878, in ban
await self._state.http.ban(user.id, self.id, delete_message_days, reason=reason)
File "C:\Users\Faisal\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\http.py", line 241, in request
raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions

I even changed the role for the bot and gave it all permission.. but nothing changed

Copy link

ghost commented Nov 20, 2020

@E40e bot try to ban server owner...

@xavierpough
Copy link

I'm also trying to get past the permissions (although I gave the bot the permission to do so in settings). Could you add me on discord XavierP.#3234 ?

@lukadd16
Copy link

lukadd16 commented Feb 8, 2021

@E40e Regardless of what permissions your bot has, it can't ban users who have roles that are above the bot's role (that's just how role hierarchy works in discord). This script doesn't account for that fact, and neither does it account for the server owner.

@LucionDiscord
Copy link

I'm sorry, if you don't like Python and using it, you shouldn't be here. Please learn discord.js.

fuck off, JS is so retarded and gay LMFAO

@vc8bp
Copy link

vc8bp commented Mar 1, 2021

Hello bro so i am getting thiss error when i am runing your script
Screenshot_2021-03-02-00-58-56-43

@Vertoxen
Copy link

Vertoxen commented Mar 8, 2021

Hello bro so i am getting thiss error when i am runing your script
Screenshot_2021-03-02-00-58-56-43

Means that it didn't find any member, try adding the bot into a server and then try again.

@swerzy0
Copy link

swerzy0 commented Mar 14, 2021

how do I add the bot to the server I want to ban everyone in?

@MahdiMZ80913
Copy link

Is this only banning everyone in the server that I ran the command in? I mean like what if my bot's in many other servers as well? It won't affect other servers?

@lukadd16
Copy link

Is this only banning everyone in the server that I ran the command in? I mean like what if my bot's in many other servers as well? It won't affect other servers?

The bot will (attempt to) ban all members that it can see (in other words, all members that it shares a server with).

@NotEG2
Copy link

NotEG2 commented May 20, 2021

It isn't working for me,
" Command raised an exception: Forbidden: 403 Forbidden (error code: 50013): Missing Permissions "
My bot has admin perms.

@lukadd16
Copy link

It isn't working for me,
" Command raised an exception: Forbidden: 403 Forbidden (error code: 50013): Missing Permissions "
My bot has admin perms.

@NotEG2 Read one of my previous comments on this matter
https://gist.github.com/daegontaven/dda3dc99c09e2c6430b09c9ae23b646b#gistcomment-3624418

@Tecno19
Copy link

Tecno19 commented Jun 23, 2021

what is the command to ban .ban or what

@WorkingCodeClickFork
Copy link

WorkingCodeClickFork commented Jul 10, 2021

Made a working verison in fork

@WorkingCodeClickFork
Copy link

Hello bro so i am getting thiss error when i am runing your script
Screenshot_2021-03-02-00-58-56-43

The reason that is its not finding any members is cause the bot has 0 intents to fix this problem enabke the members intent and it should work

Copy link

ghost commented Sep 27, 2021

I followed all the steps, but I keep getting this error
C:\Users\Faisal\Desktop>discord-ban-bot.py
Logged in!
Ignoring exception in on_ready
Traceback (most recent call last):
File "C:\Users\Faisal\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\client.py", line 333, in _run_event
await coro(*args, **kwargs)
File "C:\Users\Faisal\Desktop\discord-ban-bot.py", line 33, in on_ready
await member.ban(reason="Banned by BanBot", delete_message_days=7)
File "C:\Users\Faisal\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\member.py", line 498, in ban
await self.guild.ban(self, **kwargs)
File "C:\Users\Faisal\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\guild.py", line 1878, in ban
await self._state.http.ban(user.id, self.id, delete_message_days, reason=reason)
File "C:\Users\Faisal\AppData\Local\Programs\Python\Python37\lib\site-packages\discord\http.py", line 241, in request
raise Forbidden(r, data)
discord.errors.Forbidden: 403 Forbidden (error code: 50013): Missing Permissions

I even changed the role for the bot and gave it all permission.. but nothing changed

Same for me. Someone please help.

@JS-1191
Copy link

JS-1191 commented Nov 21, 2021

image

what should I do now

Copy link

ghost commented Nov 23, 2021 via email

@MVPHANIFA
Copy link

i need help im a hugggeeee noob actually not even that.pls friend me and hopefully u are willing to teach me.ABU#8804

@wereyupo
Copy link

I keep getting this
image

@wereyupo
Copy link

how do i fix it?

@junesties
Copy link

You guys should seriously start with the basics instead of just copy& paste any code you see into your bot. And seriously learn syntax 😅

@zZang32
Copy link

zZang32 commented Mar 13, 2022

Hey everyone, hope you're all fine, first of all you must activate this things in discord for developers (in your bot section):
image

Then paste this code to your bot:

import discord

intents = discord.Intents.all()
client = discord.Client(intents=intents)

TOKEN = ""      # Put your Bot token here
SKIP_BOTS = False

@client.event
async def on_ready():
    for member in client.get_all_members():
        try:
            if(member.bot and SKIP_BOTS):
                continue

            await member.ban(reason="message")
        except:
            print("I can't ban this user due to permissions issues: " + member.display_name)

client.run(TOKEN)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment