【发布时间】:2021-11-06 14:39:33
【问题描述】:
我的提醒命令有问题。当提醒命令运行时,它可以正常工作:它会在您提供的秒数内提醒您。但是当它运行提醒时,它不会运行任何其他命令,直到它有 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)
【问题讨论】:
-
time.sleep冻结整个过程,所以我不建议你使用time.sleep -
另外,你为什么要在函数中导入
time模块?你应该把它放在你的文件顶部
标签: python discord discord.py command bots