首页 > 解决方案 > Bot 不会清理 Messages discord.py 的特定频道

问题描述

您好,我希望机器人每 24 小时清除一次不和谐频道,我将小时数更改为秒,但仍未清除频道

import discord
from discord.ext import commands
from discord.ext import commands, tasks
import random
import datetime
import calendar
import time
from datetime import date



client = commands.Bot(command_prefix='.')


@tasks.loop(hours = 24)
async def daily_clean(ctx, bot):
  print("Successfully Purged")
  channel = client.get_channel(827603699735330837)
  await channel.purge(limit=100)

client.run("token")

标签: pythondiscorddiscord.py

解决方案


在 on_ready() 事件下启动任务。

@client.event
async def on_ready():
    print("I am ready")
    daily_clean.start()

另外,从 func 中删除ctxandbot因为我认为任务不需要/允许参数。


推荐阅读