我希望我的 python discord 机器人每分钟使用一个命令。
目前我是这样设置的:
@tasks.loop(seconds=10)
async def mytask():
channel = bot.get_channel(305347032569348107)
await channel.send('Example message')
和mytask.start()
函数中的async def on_ready()
它工作正常并发送示例消息,但我希望它实际执行一个命令,例如,我可能有另一个机器人,它有一个用于抛硬币的 !coin 命令,我希望我的机器人每分钟使用这个命令。
答案 0 :(得分:0)
如果您查看 documentation,它允许表示秒、分钟或小时:
discord.ext.tasks.loop(*, seconds=0, minutes=0, hours=0, count=None, reconnect=True, loop=None)
所以你的装饰器现在变成了:
@tasks.loop(minutes=10)
答案 1 :(得分:0)
@tasks.loop(minutes=1)
async def mytask():
channel = bot.get_channel(305347032569348107)
await channel.send(!coin)
:s