discord.py Разрабатываю собственного бота для собственного сервера. Возник вопрос: Как я могу уличить пользователя в спаме текстовыми сообщениями с помощью бота?
1 ответ
Вам необходимо создать два файла - any_name.txt
и spam_detect.txt
. Далее просто используйте этот код.
import asyncio
@client.event
async def on_ready():
print("ready")
while True:
print("cleared")
await asyncio.sleep(10)
with open("any_name.txt", "r+") as file:
file.truncate(0)
@client.event
async def on_message(message):
counter = 0
with open("spam_detect.txt", "r+") as file:
for lines in file:
if lines.strip("\n") == str(message.auth.id):
counter+=1
file.writelines(f"{str(message.author.id)}\n")
if counter > 5:
await message.guild.ban(message.author, readon="spammer")
await syncio.sleep(1)
await message.guild.unban(message.author)
print("Oops")
Автор - https://raviblog.medium.com/how-to-make-a-discord-antispam-bot-using-python-6f0f90a7c307