How can I reset a command cooldown for a discord user?

Viewed 388

I would like to avoid as many errors as possible, but the bot may have errors during its runtime. You can run a command only once every 7 days. If it comes to errors that would be doofy of course. Is there a way to make a command usable once again/reset the cooldown for certain users?

My approach:

    @trivia_channel.command(aliases=["reset"])
    async def reset_cooldown(self, ctx, member: discord.Member):
        await self.start.reset_cooldown(ctx, member)
        await ctx.send(f"Resetted cooldown for {member}.")

trivia_channel.command is a group command.

This obviously throws errors and I don't know how to accommodate the member argument.

1 Answers

Command.reset_cooldown only takes one argument, the Context. You can reset the cooldown for someone else if you overwrite the Context.author and Context.message.author attributes with the member variable.

@trivia_channel.command(aliases=["reset"])
async def reset_cooldown(self, ctx, member: discord.Member):
    ctx.author = member
    ctx.message.author = member
    
    self.start.reset_cooldown(ctx)
    await ctx.send(f"Resetted cooldown for {member.mention}")

This worked for me, it's not the best solution though. If you want a much better way you can create a custom cooldown but it's not worth for only one command.

Reference:

Related