首页 > 解决方案 > 对于不和谐的python,如何每x秒打印一条带有任务的消息?

问题描述

例如,我试图每 10 秒在普通聊天中打个招呼。我怎么做?我正在使用任务功能。

channel = client.get_channel('channel id') 
@tasks.loop(seconds=10)
async def sendmessage():
    await channel.send("hello")

标签: pythondiscord.py

解决方案


您可以使用 `.start() 启动任务

channel = client.get_channel('channel id') 
@tasks.loop(seconds=10)
async def sendmessage():
    await channel.send("hello")

sendmessage.start()

推荐阅读