Skip to content

Instantly share code, notes, and snippets.

@andgate
Created December 25, 2021 23:36
Show Gist options
  • Save andgate/86db6d0a3d89618f0c6cf1b738d5a14f to your computer and use it in GitHub Desktop.
Save andgate/86db6d0a3d89618f0c6cf1b738d5a14f to your computer and use it in GitHub Desktop.
Discord script to nuke bot spam
# bot.py
'''
> Instructions
0) Configure the script constants (TOKEN, GUILD_ID, BOT_CHANNEL_ID_LIST, BOT_ID)
1) Download and install python: https://www.python.org/downloads/
2) Open command prompt, navigate to this script folder.
3) Install discord.py with the following command: pip install discord
4) Run the script with the command: python bot.py
'''
import discord
TOKEN = 'DISCORD_TOKEN'
GUILD_ID = 123
BOT_CHANNEL_ID_LIST = [ 1234 ]
BOT_ID = 1234
client = discord.Client()
def is_not_bot_channel(c):
channel_id = c.id
return not any(map(lambda id: id == channel_id, BOT_CHANNEL_ID_LIST))
def is_bot_spam(m):
return m.author.id == BOT_ID
@client.event
async def on_ready(self):
print(f'Logged in as {self.user} (ID: {self.user.id})')
print('------')
# Get the guild
guild = client.get_guild(GUILD_ID)
print(
f'{client.user} is connected to the following guild:\n'
f'{guild.name}(id: {guild.id})'
)
# Get the list on non-bot channels
channels = filter(is_not_bot_channel, guild.text_channels)
print(f'{client.user} is connected to the following channels:')
for channel in channels:
print(f'{channel.name}(id: {channel.id})')
# Purge each channel
for channel in channels:
deleted = await channel.purge(limit=None, check=is_bot_spam)
print(f'deleted {len(deleted)} bot spam message(s) from channel {channel.name})')
client.run(TOKEN)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment