Skip to content

Instantly share code, notes, and snippets.

@judge2020
Created February 19, 2017 19:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save judge2020/4a6e2266c091c7eab7b43057554988e1 to your computer and use it in GitHub Desktop.
Save judge2020/4a6e2266c091c7eab7b43057554988e1 to your computer and use it in GitHub Desktop.
Delete non-image attachments discord - discord.py
#!/usr/bin/python
# python 3
# requires https://github.com/Rapptz/discord.py / "pip install discord.py"
# licensed under the MIT license. For more information view LICENSE.md
import discord
import asyncio
import os.path
import re
import sys
from pathlib import Path
# CONFIG START -------
whiteList = ['bmp','jpeg','jpg','png']
# CONFIG END -------
client = discord.Client()
@client.event
async def on_ready():
print('Logged in as')
print(client.user.name)
print(client.user.id)
print('------')
@client.event
async def on_message(message):
try:
for attachment in message.attachments:
if attachment['filename'].split('.')[-1] not in whiteListArray:
client.delete_message(message)
except:
print('Unknown error')
if os.path.exists('token.txt'):
tokenfile = open('token.txt', 'r')
token = tokenfile.read()
tokenfile.close()
client.run(token)
else:
token = input('Please input token: ')
os.system('cls' if os.name == 'nt' else 'clear')
client.run(token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment