在discord.py 中设置超时?

发布于 2025-01-15 06:36:28 字数 2649 浏览 0 评论 0原文

我有这段代码,我希望它也像 Discord.js 中的 setTimeout 函数一样工作,但我不知道如何。我希望这段代码在嵌入中显示一个老虎机,并且每次旋转时,第二条消息都会针对其旋转的每个字母进行自我编辑。我有这些参考代码: https://cdn.discordapp.com/attachments/948236057097416766/954472309748555896/unknown.png https://cdn.discordapp.com/attachments/948236057097416766/954472151866564678/unknown.png https://cdn.discordapp.com/attachments/948236057097416766/954472868790546462/unknown.png https://cdn.discordapp.com/attachments/948236057097416766/954472868790546462/unknown.png https://cdn.discordapp.com/attachments/948236057097416766/954473890883715092/unknown.png

来自朋友,他使用 .js 这是我的插槽代码:

#slots 
@client.command()
async def slot(ctx,amount = None):
  await open_account(ctx.author)
  if amount == None:
    em = discord.Embed(title='ERROR:', description='Please specify a amount you want to put in the slot!', color=0xff0000)
    await ctx.send(embed = em) 
    return

  bal = await update_bank(ctx.author)

  amount = int(amount)
  if amount>bal[0]:
    em = discord.Embed(title='ERROR:', description="You don't have enough money!", color=0xff0000)
    await ctx.send(embed = em) 
    return
  if amount<10:
    em = discord.Embed(title='ERROR:', description="Put a amount of ``10-70`` in the slot machine!", color=0xff0000)
    await ctx.send(embed = em) 
    return
  if amount>70:
    em = discord.Embed(title='ERROR:', description="Put a amount of ``10-70`` in the slot machine!", color=0xff0000)
    await ctx.send(embed = em) 
    return

  final = []
  for i in range(3):
      a = random.choice([':regional_indicator_x:',':regional_indicator_o:',':regional_indicator_q:',':regional_indicator_g:',':regional_indicator_u:'])
    
      final.append(a)
  em3 = discord.Embed(title='Slot:', description=f'{final}', color=0xff000)
  em3 = set.Image('https://cdn.discordapp.com/attachments/844618714439483435/954485256021508156/ezgif.com-gif-maker.gif')
  await ctx.send(embed = em3)

正如你在最后一行看到的那样尝试添加该插槽 GIF。但我希望它旋转 3 次,然后它下面的消息随之改变...我试图尽可能地阐明我的目标!

I have this code and i want it too work like a setTimeout function in discord.js but i dont know how. I want this code to show a slot machine in the embed and every time it spins, the second message edits itself for every letter it spins. I have these reference codes:
https://cdn.discordapp.com/attachments/948236057097416766/954472309748555896/unknown.png
https://cdn.discordapp.com/attachments/948236057097416766/954472151866564678/unknown.png
https://cdn.discordapp.com/attachments/948236057097416766/954472868790546462/unknown.png
https://cdn.discordapp.com/attachments/948236057097416766/954472868790546462/unknown.png
https://cdn.discordapp.com/attachments/948236057097416766/954473890883715092/unknown.png

from a friend and he uses .js This is my code for slots:

#slots 
@client.command()
async def slot(ctx,amount = None):
  await open_account(ctx.author)
  if amount == None:
    em = discord.Embed(title='ERROR:', description='Please specify a amount you want to put in the slot!', color=0xff0000)
    await ctx.send(embed = em) 
    return

  bal = await update_bank(ctx.author)

  amount = int(amount)
  if amount>bal[0]:
    em = discord.Embed(title='ERROR:', description="You don't have enough money!", color=0xff0000)
    await ctx.send(embed = em) 
    return
  if amount<10:
    em = discord.Embed(title='ERROR:', description="Put a amount of ``10-70`` in the slot machine!", color=0xff0000)
    await ctx.send(embed = em) 
    return
  if amount>70:
    em = discord.Embed(title='ERROR:', description="Put a amount of ``10-70`` in the slot machine!", color=0xff0000)
    await ctx.send(embed = em) 
    return

  final = []
  for i in range(3):
      a = random.choice([':regional_indicator_x:',':regional_indicator_o:',':regional_indicator_q:',':regional_indicator_g:',':regional_indicator_u:'])
    
      final.append(a)
  em3 = discord.Embed(title='Slot:', description=f'{final}', color=0xff000)
  em3 = set.Image('https://cdn.discordapp.com/attachments/844618714439483435/954485256021508156/ezgif.com-gif-maker.gif')
  await ctx.send(embed = em3)

as you can see on the last line i try to add that slots GIF. But i want it to spin 3 times and then the messages under it changes with it... I tried to clarify my goal with this a good as possible!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无言温柔 2025-01-22 06:36:28

相当于 JavaScript 的 setTimeout 函数的 python 是 time.sleep

time.sleep 的一个示例用法是:

await ctx.send(embed = em)
sleep(200)
await ctx.send(embed = em3)

The python equivalent to JavaScript's setTimeout function is time.sleep.

An example usage of time.sleep is:

await ctx.send(embed = em)
sleep(200)
await ctx.send(embed = em3)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文