在python中嵌入的不和谐中显示python睡眠函数的倒计时 [英] Display a countdown for the python sleep function in discord embed in python

查看:58
本文介绍了在python中嵌入的不和谐中显示python睡眠函数的倒计时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个不和谐的机器人

hi all I am doing one discord bot

我需要发送一个倒计时,就像在每次请求后嵌入一个冷却时间

I need to send one countdown it's like a cooldown embed after every request

我做了这段代码,但是我不知道如何在嵌入中添加它

I did this code but I don't know how to add this in my embed

 for i in range(60,0,-1):
     print(f"{i}", end="\r", flush=True)
     time.sleep(1)

这是我的嵌入内容:

embed_processing = discord.Embed(
                title = ('please wait 1min we are processing your request time '),
                description=('Jaffa_the_warrior server'),
                colour = discord.Color.orange()
            )
            processingmessage = await ctx.channel.send(embed = embed_processing)

请帮我,我想在标题中添加一个计时器

please help me i want to add a timer in the title

推荐答案

import asyncio

@bot.command()
async def count(ctx, duration:int):
  msg = await ctx.send("Started")
  for i in range(duration, -1, -1):
    m, s = divmod(i, 60)
    await msg.edit(content="{0:02}:{1:02}".format(m, s))
    await asyncio.sleep(1)

这是计时器命令,但如果调用的次数大于1,则无法正常工作.

This is the timer command but not working good if called more then 1.

这篇关于在python中嵌入的不和谐中显示python睡眠函数的倒计时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆