首页 > 解决方案 > 提醒命令问题

问题描述

我的提醒命令有问题。当提醒命令运行时,它可以正常工作:它会在您提供的秒数内提醒您。但是当它运行提醒时,它不会运行任何其他命令,直到它有 DM 提醒你。

这是代码。我不太擅长解释;你可以问问题。

@client.command()
async def remindersec(ctx,seconds=None):
  try:
    embed = discord.Embed(title = f"I will remind you in {seconds} seconds",
    description = f"You'll be DMed as a reminder.",
    color = 0xf461ff)

    now = datetime.now()
    current_time = now.strftime("%H:%M")

    embed.set_footer(text=f"Requested by  {ctx.author} at {current_time}")

    await ctx.send(embed=embed)
    timer = int(seconds)
    while timer >= 0:
      import time
      time.sleep(1)
      timer -= 1
    await ctx.author.send("Reminder!")
  except ValueError:
    embed = discord.Embed(title = "Error!",
    description = f"Please type a valid number.",
    color = 0xf461ff)

    now = datetime.now()
    current_time = now.strftime("%H:%M")

    embed.set_footer(text=f"Requested by  {ctx.author} at {current_time}")

    await ctx.send(embed=embed)
  except TypeError:
    embed = discord.Embed(title = "Error!",
    description = f"Please type a valid number.",
    color = 0xf461ff)

    now = datetime.now()
    current_time = now.strftime("%H:%M")

    embed.set_footer(text=f"Requested by  {ctx.author} at {current_time}")

    await ctx.send(embed=embed)

标签: pythondiscorddiscord.pycommandbots

解决方案


不要使用时间模块。使用异步。所以它会像: -

import asyncio

timer = int(seconds)
while timer >= 0:
  await asyncio.sleep(1)
  timer -= 1
  await ctx.author.send("Reminder!")
except ValueError:
  embed = discord.Embed(title = "Error!",
  description = f"Please type a valid number.",
  color = 0xf461ff)

推荐阅读