有没有办法制作一个每秒钟更新一次的计时器,这样我就可以看到我的程序运行了多长时间。我试着做一个循环:
i = 0
for i in range(1000000):
i += 1
time.sleep(1)
然后我想把它打印到我的discord.py机器人上。这就是它的样子:
async def on_ready():
os.system('cls')
print('', fg('red'))
print(' _____ _ ', fg('red'))
print('| ___| | __ _ _ __ _ __ _ _ ', fg('red'))
print("| |_ | |/ _` | '_ \| '_ \| | | |", fg('red'))
print('| _| | | (_| | |_) | |_) | |_| |', fg('red'))
print('|_| |_|\__,_| .__/| .__/ \__, |', fg('red'))
print(' |_| |_| |___/ ', fg('red'))
print(f'Up-Time: {i}')
print(f'Version: {version}', fg('blue'))
print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~', fg('green'))
print('[Server]: The Bot is online.', fg('green'))
“Up Time”是我希望显示时间的地方,但当我尝试运行它时,没有显示任何内容。但是,当我将print(i)放在循环下面时,它所做的唯一事情就是打印出数字,而不让实际的服务器运行
抱歉,如果解释不够好,我是StackOverFlow和编程的新手。如果打扰您,请原谅,提前谢谢您
您不应该将
time.sleep
与discord.py
一起使用,因为它将停止您应该使用的整个botawait asyncio.sleep(1)
也可以创建此命令
现在您可以使用
{prefix}uptime
它将告诉您它已经运行了多长时间您可以通过多线程来实现这一点。您的函数随时间运行,两个函数在函数运行完成后立即终止:
相关问题 更多 >
编程相关推荐