在一个反垃圾邮件机器人上工作,它将作者in记录到一个.txt文件(每10秒清除一次),这段代码运行,但我没有看到任何作者的名字填充在我的txt文件中。
任何帮助都将不胜感激。
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..")发布于 2022-01-12 02:38:13
结果发现我在异步def @client.event之前缺少了on_message。
https://stackoverflow.com/questions/70673670
复制相似问题