1@client.event #don't forget to add import import asyncio also
2async def on_ready():
3 print("ready")
4 while True:
5 print("cleared")
6 await asyncio.sleep(10)
7 with open("spam_detect.txt", "r+") as file:
8 file.truncate(0)
9
10@client.event
11async def on_message(message):
12 counter = 0
13 with open("spam_detect.txt", "r+") as file:
14 for lines in file:
15 if lines.strip("\n") == str(message.author.id):
16 counter+=1
17
18 file.writelines(f"{str(message.author.id)}\n")#bans the user spamming
19 if counter > 5:
20 await message.guild.ban(message.author, reson="spam")
21 await asyncio.sleep(1)
22 await message.guild.unban(message.author)
23 print("uh oh")