首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用discord.py在反垃圾邮件机器人上工作--这段代码运行但不做它应该做的事情

使用discord.py在反垃圾邮件机器人上工作--这段代码运行但不做它应该做的事情
EN

Stack Overflow用户
提问于 2022-01-11 21:29:16
回答 1查看 277关注 0票数 1

在一个反垃圾邮件机器人上工作,它将作者in记录到一个.txt文件(每10秒清除一次),这段代码运行,但我没有看到任何作者的名字填充在我的txt文件中。

  • 注意,我删除了带有用户键的代码部分,所以我所列出的只是与实际反垃圾邮件功能相关的代码。

任何帮助都将不胜感激。

代码语言:javascript
复制
import asyncio
import os
import json
import time
import random
import discord
import datetime

from discord.ext import commands
from discord.ext.commands import bot

    ## On Logon ##
    @client.event
    async def on_ready():
        print("Ready")
        while True:
            print("cleared")
            await asyncio.sleep(10)
            with open("spam-bank.txt", "r+") as file:
                file.truncate(0)

    async def on_message(message):
    counter = 0
    with open("spam-bank.txt", "r+") as file:
        for lines in file:
            if lines.strip("\n") == str(message.author.id):
                counter+=1
        
        file.writelines(f"{str(message.author.id)}\n")
        if counter > 5:
            await message.guild.ban(message.author, reason="Caught by bot Spamming")
            await asyncio.sleep(1)
            await message.guild.unban(message.author)
            print("Flagged by bot for spamming chat..")
EN

回答 1

Stack Overflow用户

发布于 2022-01-12 02:38:13

结果发现我在异步def @client.event之前缺少了on_message。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70673670

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档