您可以执行一个函数来检查要重置冷却时间的成员和另一个函数“before_invoke”在命令运行之前检查第一个函数,如果是,则重置冷却时间
def check_if_it_is_me(ctx):
return ctx.message.author.id == 759027058613026827
class ImaCog(commands.Cog, name='Imagens'):
"""Gifs e imagens para você se divertir"""
def __init__(self, bot):
self.bot = bot
async def cog_before_invoke(self, ctx: commands.Context):
if check_if_it_is_me(ctx):
return ctx.command.reset_cooldown(ctx)
@commands.command(brief='Manda uma piscadinha',
help='Use o comando para ver uma pisacadinha aleatória de algum anime. Você pode enviar a '
'piscadinha para alguem marcando a pessoa no comando')
@commands.cooldown(1, 5, commands.BucketType.user)
async def pisque(self, ctx, quem: discord.Member = None):
gif = await buscar('animu', 'wink')
await ctx.send(ctx.author.mention,
embed=gera_embed(ctx=ctx, link=gif, membro=quem,
acao_s='piscou', acao_c='mandou uma piscada para'))
此 cog 中的所有命令都有一个“@ commands.cooldown (1, 5, commands.BucketType.user)”,限制每个用户每 5 秒使用一次命令。但在每个 cog 命令之前,调用“async def cog_before_invoke”,然后调用“check_if_it_is_me”函数,如果命令的作者是我,则返回 true,然后返回“async def cog_before_invoke”函数,如果“check_if_it_is_me”功能为真。如果“check_if_it_is_me”函数为false(不是我使用该命令),“cog_before_invoke”函数不会重置冷却时间,命令作者需要正常等待冷却时间。
您可以为“check_if_it_is_me”功能添加更多参数,例如无需等待冷却时间的成员列表或冷却时间无效的时间,但这取决于您
我希望它很清楚,祝你好运