如何在没有人输入命令的情况下清除通道中的消息



我想制作一个机器人程序,每个星期天删除频道中的所有内容,我已经记下了日期,但我不明白如果没有人运行命令告诉机器人程序删除所有内容,如何删除某个频道中的每个消息?

到目前为止我的代码

import discord
from discord.ext import commands
import random
import datetime
from datetime import date
import calendar

client = commands.Bot(command_prefix='.')
has_cleaned_channel = 0
date = datetime.date(2021,4,4)
if date == date.today():
if has_cleaned_channel == 0:
print("Date is Sunday")
print(date.today())
has_cleaned_channel = 1
date2 = datetime.date(2021,4,5)
if date2 == date.today():
has_cleaned_channel = 0

client.run("TOKEN")

好吧,在做任何其他事情之前,你需要重置你的discord bot令牌。您刚刚将其包含在问题中,并使您的应用程序容易被劫持。所以请立即更改!

关于你的问题,你会想使用任务。

from discord.ext import commands, tasks
@tasks.loop(hours=24)
async def daily_clean():
channel = bot.get_channel(channelid)
await channel.purge(limit=100)

最新更新