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

时间:2021-04-03 15:51:45

标签: python discord discord.py

我想制作一个机器人,它可以在每个星期天删除频道中的所有内容,我已经将日期记下来了,但是我不明白如何在没有人运行命令机器人的情况下删除某个频道中的每条消息删除所有内容,有什么办法吗?

到目前为止我的代码

    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")

1 个答案:

答案 0 :(得分:2)

好的,在你做任何其他事情之前,你需要重置你的不和谐机器人令牌。 您刚刚将其包含在问题中,并使您的应用程序容易受到劫持。所以请马上更改!

关于您的问题,您需要使用任务。

from discord.ext import commands, tasks

@tasks.loop(hours=24)
async def daily_clean():
    channel = bot.get_channel(channelid)
    await channel.purge(limit=100)