0

discord.py Разрабатываю собственного бота для собственного сервера. Возник вопрос: Как я могу уличить пользователя в спаме текстовыми сообщениями с помощью бота?

1 ответ 1

0

Вам необходимо создать два файла - 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

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.