【发布时间】:2018-03-08 02:23:05
【问题描述】:
我试图让命令仅在 discord.py 中的特定时间内工作,有什么方法可以创建选择语句或使用 asyncio 函数?这是我的一些代码:
@client.command(pass_context=True)
async def pick(ctx):
oneto5 = str(random.randrange(1, 5))
await client.say("You recived " + oneto5 + " fish")
更新 这是我更新的代码,但它似乎给了我不稳定的输出。它没有正确迭代。
@client.command(pass_context=True)
async def pick(ctx):
sec = localtime().tm_sec
count = 0
print(sec)
while (300 >= sec):
if (1 <= lowFishRange <= 20):
oneto5 = str(5)
await client.say("You recived " + oneto5 + " fish")
await asyncio.sleep(43200)
return
else:
oneto5 = str(1)
await client.say("You recived " + oneto5 + " fish")
await asyncio.sleep(43200)
return
else:
await client.say("You seemed to have missed the mark, try again when a message appears...")
await asyncio.sleep(43200)
return
【问题讨论】:
-
tm_sec将是[0, 61]范围内的整数。所以300 >= sec总是正确的。300是什么? -
只是一个 300 秒的数字文字。我想我应该使用分钟。我想我可以解决这个问题。如果它也不能按照我想要的方式工作,我稍后会再发一篇文章。另外,非常感谢。你帮了我不少忙。我欠你一个。
标签: python-3.x python-asyncio discord discord.py