【问题标题】:Display a countdown for the python sleep function in discord embed in python在 python 中嵌入的不和谐中显示 python 睡眠功能的倒计时
【发布时间】:2021-07-17 15:58:04
【问题描述】:

大家好,我正在做一个不和谐的机器人

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

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

 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)

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

【问题讨论】:

  • 您是否尝试过定义您的方法?您也可以在一定时间后编辑消息。请记住time.sleep 已经过时了,请尝试使用asyncio.sleep

标签: python discord.py


【解决方案1】:
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 个,则无法正常工作。

【讨论】:

  • 我尝试在我的机器人上运行它,它运行良好。可以分享一下代码吗?
  • 实际上你发送的原因是用户发送!计数 5 然后它会计数,但我需要在用户发送消息后立即开始倒计时这是我的复制链接请帮助我replit.com/join/hmvkdkae-balajikotni
猜你喜欢
  • 1970-01-01
  • 2021-12-01
  • 2011-02-03
  • 2012-07-24
  • 1970-01-01
  • 1970-01-01
  • 2015-07-04
  • 2013-06-17
相关资源
最近更新 更多