【发布时间】:2020-07-18 02:08:06
【问题描述】:
我试图让一个不和谐的机器人每 30 分钟发送一条消息,我能想出的唯一解决方案变得非常奇怪,它会开始以看似随机的间隔发送消息并一次发送多个消息。
这里是受影响的代码:
@client.event
async def on_ready():
await test()
async def test():
print("running test")
channel = client.get_channel(PLACEHOLDER)
await channel.send("i like " +words)
print(words)
await asyncio.sleep(1800)
await test()
我尝试用 time.sleep 替换 asyncio.sleep 但这会导致机器人超时并从 on_ready 和本身运行 test() 函数导致它发送两次消息,我会在一致的基础上.我和几个朋友已经搞砸了一段时间,无法修复它。
【问题讨论】:
标签: python-3.x python-asyncio discord.py-rewrite