我正在使用Python .
这是一个示例命令:
@client.command(pass_context=True)
async def enablesentience(ctx):
await client.say(":desktop: | User does not have sufficient permissions.")
当触发命令'enablesentience'时,机器人在聊天中说:
:桌面:|用户没有足够的权限 .
我正在寻找的是一种为此命令添加冷却时间的方法,这样一个人每隔几秒就可以使用一次命令 . 如果在冷却时间内尝试命令,我希望机器人在聊天中说出剩余的冷却时间 .
我试过了:
@client.command(pass_context=True)
@commands.cooldown(1, 30, commands.server.user)
async def enablesentience(ctx):
await client.say(":desktop: | User does not have sufficient permissions.")
和
async def cooldown(1, 5, type=server.default)
@client.command(pass_context=True)
async def enablesentience(ctx):
await client.say(":desktop: | User does not have sufficient permissions.")
其中只给出了''Command'对象没有属性'cooldown''和语法错误 .
任何帮助将不胜感激,并提前感谢您 .
1 回答
你的第一次尝试几乎是正确的 - 你需要指定一个
BucketType
来代替“commands.server.user
”,如下所示:您可以选择多个存储桶 . 它们都在源代码中here.(
default
表示全局 . )