python - 提醒命令问题
问题描述
我的提醒命令有问题。当提醒命令运行时,它可以正常工作:它会在您提供的秒数内提醒您。但是当它运行提醒时,它不会运行任何其他命令,直到它有 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)
解决方案
不要使用时间模块。使用异步。所以它会像: -
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)
推荐阅读
- php - Wordpress WooCommerce 'woocommerce_hidden_order_itemmeta' 过滤器挂钩未触发
- linux - BASH脚本中For循环中的操作数错误?
- android - 底部导航栏的 onItemSelectedListener
- python - Python For 循环中的属性错误(返回无) - 雅虎财经
- c++ - 无法在编译时将数组转换为字符串视图
- php - 在服务器上部署 laravel 8 时,它显示文件夹结构
- kubernetes - Terraform:尝试销毁 EKS 集群时出现“错误:删除 S3 存储桶时出错”
- python - 如何创建按列和列值过滤的函数?
- python - Pyaudio 未作为模块找到
- r - R嵌套所有列而不是列表