好吧,基本上,我写了这段代码,它说
File "C:\Users\jellis\Desktop\Suggestion Bot\bot.py", line 28, in <module>
@commands.cooldown(1, 1500, ctx)
NameError: name 'ctx' is not defined我尝试将@commands.cooldown(1,1500 ctx)移到async def suggest(ctx, *args)之后,但它给出了相同的错误。
@bot.command(pass_context = True)
@commands.cooldown(1, 1500, ctx)
async def suggest(ctx, *args):
mesg = ' '.join(str(*args))
embed = discord.Embed(title='New Suggestion', description='-----------', color=0x4C4CE7)
if chatFilter in mesg:
await bot.say(':x: Suggestion Could Not Be Sent.')
elif chatFilter not in mesg:
embed.add_field(name='{}'.format(ctx.message.author.display_name), value='{}'.format(mesg))
await bot.send_message(discord.Object(id=suggestionsChannelID), embed=embed)
white_check_mark = get(bot.get_all_emojis(), name='white_check_mark')
await bot.add_reaction(message, white_check_mark)
x = get(bot.get_all_emojis(), name='x')
await bot.add_reaction(message, x)
suggestionCount = suggestionCount + 1
else:
raise error
@bot.error
async def bot_error(error, member: discord.Member, ctx):
if isinstance(error, commands.CommandOnCooldown):
msg = ':x: {member} This command on cooldown, please try again in `{:.2f}s`'.format(error.retry_after)
await bot.send_message(ctx.message.channel, msg)
else:
raise error我希望它能检测到命令处于冷却状态,然后运行@bot.error事件。
发布于 2019-05-28 02:56:44
你的冷却时间将永远不会被激活,并且总是会遇到错误。因为,由于ctx是Bot的Context-Container,所以不能作为属性放在那里。
@commands.cooldown的指定方式如下:
discord.ext.commands.cooldown(rate, per, type=<BucketType.default: 0>)您必须使用要使用的Bucket而不是Context-Container (ctx)来传递Enum。
您可以使用的可用存储桶包括:
BucketType.default for a global basis.
BucketType.user for a per-user basis.
BucketType.guild for a per-guild basis.
BucketType.channel for a per-channel basis.
BucketType.member for a per-member basis.
BucketType.category for a per-category basis.有关更多信息,您可以在此处找到Discord Documentation。
https://stackoverflow.com/questions/56330683
复制相似问题