我是 Python 新手(我在学校课程中学习了基础知识),
目前我正在尝试为我的不和谐服务器创建简单的机器人。
目前,我真正想要的机器人是一个自动删除机器人,因此我可以说,(例如)在 24 小时后删除 ...Channel 中的每条消息。因为我真的不想手动完成。
我知道有一些很好的机器人可以做到这一点,
但是例如MEE6要我购买Premium来使用funktion。另一个我不想使用任何成品机器人的原因是我真的很想理解和学习代码,
我看了很多教程,并试图将我理解的脚本部分放在一起,但没有奏效。我也没有找到向我解释它的教程,以便我理解,所以现在我在这里并希望我能理解它。
我希望有一些人来帮助我。 :)
谢谢
-Yami.Code
@bot.event()
async def on_ready(ctx):
while requirement == 1:
await ctx.channel.purge
time.sleep(20)
#错误是:
line 11, in <module>
@bot.event()
TypeError: event() missing 1 required positional argument: 'coro'
Process finished with exit code 1
答案 0 :(得分:0)
bot.event
(去掉括号),time.sleep
是阻塞调用,请改用 asyncio.sleep
(What does "blocking" mean)on_ready
不以 ctx
作为参数,如果你想向频道发送消息,你应该先获取频道对象,然后使用 send
方法< /li>
channel.purge
方法中缺少括号...import asyncio # if you haven't already
@bot.event
async def on_ready():
channel = bot.get_channel(channel_id) # replace `channel_id` with an actual channel ID
while requirement == 1:
await channel.purge(limit=x) # change `x` accordingly...
await asyncio.sleep(20)