Python 测试命令是否处于冷却状态
如果有人试图执行命令时,我的命令当前处于冷却状态,我只想向玩家发送一条消息,说明命令处于冷却状态Python 测试命令是否处于冷却状态,python,python-3.x,discord.py,Python,Python 3.x,Discord.py,如果有人试图执行命令时,我的命令当前处于冷却状态,我只想向玩家发送一条消息,说明命令处于冷却状态 @bot.command(pass_context=True) @commands.cooldown(1, 30, commands.BucketType.user) async def cooldown_test(ctx): await bot.say("Hello!") # If the bot is on cooldown then: # await bot.say("
@bot.command(pass_context=True)
@commands.cooldown(1, 30, commands.BucketType.user)
async def cooldown_test(ctx):
await bot.say("Hello!")
# If the bot is on cooldown then:
# await bot.say("On cooldown!")
这是abccd写在副本上的答案
from discord.ext import commands
bot = commands.Bot('$')
@bot.event
async def on_command_error(error, ctx):
if isinstance(error, commands.CommandOnCooldown):
await bot.send_message(ctx.message.channel, content='This command is on a %.2fs cooldown' % error.retry_after)
raise error # re-raise the error so all the errors will still show up in console
@bot.command(pass_context=True)
@commands.cooldown(1, 30)
async def getalt(ctx):
await bot.send_message(ctx.message.channel, content='in getalt')
bot.run('token')
报告内容丰富。特别是查看CommandOnColdOwn异常。我使用了“try:”代码和“exception CommandOnColdOwn:”以及bot.say但什么也没发生。nod,raise commandOnColdOwn
在master中不再存在。您正在使用的特定库版本的详细信息(问题似乎不包括)很重要。(也就是说,也许你可以自己阅读源代码?)。您只需检查是否引发了commandoncoldown
。请记住,如果不是,请重新评估错误…在问题标题中添加“已解决”是严格违反网站政策的,并且会破坏公认答案的意义。请不要这样做。这是一个信息。特别是查看CommandOnColdOwn异常。我使用了“try:”代码和“exception CommandOnColdOwn:”以及bot.say但什么也没发生。nod,raise commandOnColdOwn
在master中不再存在。您正在使用的特定库版本的详细信息(问题似乎不包括)很重要。(也就是说,也许你可以自己阅读源代码?)。您只需检查是否引发了commandoncoldown
。请记住,如果不是,请重新评估错误…在问题标题中添加“已解决”是严格违反网站政策的,并且会破坏公认答案的意义。请不要这样做。