python - 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")
解决方案
在 on_ready() 事件下启动任务。
@client.event
async def on_ready():
print("I am ready")
daily_clean.start()
另外,从 func 中删除ctx
andbot
因为我认为任务不需要/允许参数。
推荐阅读
- docker - 将 Django 部署到 App Engine 柔性环境 - 超时错误响应:[4]
- python - python - 召回浏览过的文件
- android - Android 5 中的崩溃 - 在 onResume 中抛出 IllegalStateException
- mysql - 在 my.cnf 文件中,将 bind-address 更改为 127.0.0.1 并且它仍然允许远程连接
- spring - 如何在春季加载多个骆驼上下文
- java - 无论如何使用java程序在docker容器中获取主机Mac和IP地址
- asp.net-mvc - Blazor 如何仅在具有相同类的一个元素上添加/删除类而不是全部
- c# - C#中的即兴问题
- html - 谁能告诉我如何在同一行中生成 div,即使它们是块元素?
- glom - 用glom切片水平