python - 如何为不和谐用户重置命令冷却时间?

标签 python discord discord.py

我想尽可能避免错误,但机器人在运行期间可能会出错。您每 7 天只能运行一次命令。如果涉及到错误,那当然是愚蠢的。有没有办法让命令再次可用/为某些用户重置冷却时间?

我的方法:

    @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 是组命令。

这显然会引发错误,我不知道如何适应 member 参数。

最佳答案

Command.reset_cooldown 只接受一个参数,Context。如果您用 member 变量覆盖 Context.authorContext.message.author 属性,您可以为其他人重置冷却时间。

@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}")

这对我有用,但它不是最佳解决方案。如果您想要一种更好的方法,您可以创建自定义冷却时间,但仅使用一个命令是不值得的。

引用:

关于python - 如何为不和谐用户重置命令冷却时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65916727/

相关文章:

python - 64GB 可用,超过 16GB 时 cv2/python 崩溃

python - 如何返回符合 driver.find_element_by_partial_link_text 标准的最后一个元素?

javascript - Discord.js SQLITE_ERROR : table scores has no column named points

discord - 如何对特定消息使用react (discord.py)

Python Bot 使用自定义表情符号

python - 两个 Amazon S3 Python Boto 上传问题

python - E : Could not get lock/var/cache/apt/archives/lock - open (11: Resource temporarily unavailable)

discord - 如何让我的 Discord 机器人每 10 秒更改一次状态?

discord - 我正在尝试使用 discord.py 构建歌词命令,但出现此错误。关于我做错了什么以及如何修复它有什么想法吗?

python - Discord 机器人检查机器人是否删除了消息