[英]How to reset cooldown of a command discord.py
I am trying to reset the cooldown if reacted with ❌.如果对❌做出反应,我正在尝试重置冷却时间。 I tried
_set.reset_cooldown(self, ctx)
and commands.Command.reset_cooldown
but they didn't work.我尝试
_set.reset_cooldown(self, ctx)
和commands.Command.reset_cooldown
但它们没有用。 Am I doing something wrong?难道我做错了什么? Can someone help me?
有人能帮我吗?
@prefix.command(aliases=["set"])
@commands.has_permissions(manage_messages=True)
@commands.cooldown(1, 20, commands.BucketType.guild)
async def _set(self, ctx, prefix):
embed = discord.Embed(
title="Prefix Change",
description=f"Are you sure you want to change the prefix for Umbra to `{prefix}` in {ctx.guild}?",
colour=ctx.author.color
)
message = await ctx.send(embed=embed)
await message.add_reaction("✅")
await message.add_reaction("❌")
def check(reaction, user):
if reaction.message.id == message.id:
return user == ctx.author and str(reaction.emoji) in ["✅", "❌"]
else:
return
while True:
try:
reaction, user = await self.bot.wait_for("reaction_add", timeout=180, check=check)
if str(reaction.emoji) == "✅":
client.query(
q.update(
q.select(['ref'], q.get(
q.match(
q.index("prefixByGuildID"), f"{ctx.guild.id}"
)
)
), {"data": {"guildID": f"{ctx.guild.id}", "prefix": f"{prefix}"}}
)
)
conftrue = discord.Embed(
title="Prefix Change",
description=f"Prefix changed to `{prefix}` successfully!",
colour=0x55ff55
)
await message.edit(embed=conftrue)
await message.clear_reactions()
elif str(reaction.emoji) == "❌":
conffalse = discord.Embed(
title="Prefix Change",
description=f"Prefix change cancelled.",
colour=0xff5555
)
await message.edit(embed=conffalse)
await message.clear_reactions()
else:
await message.remove_reaction(reaction, user)
except asyncio.TimeoutError:
break
Also yes I am using my own confirmation system, please don't ask me to use an existing library, I like the way it is.另外是的,我正在使用我自己的确认系统,请不要让我使用现有的库,我喜欢它的方式。
You can simply do你可以简单地做
ctx.command.reset_cooldown(ctx)
You don't pass any other arguments than the Context
除了
Context
之外,您没有传递任何其他 arguments
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.