#python #discord.py
Вопрос:
Я создаю систему экономии для своего бота и перезарядку для команды beg.
Команда работает, перезарядка работает, но она ничего не говорит, когда команда находится на перезарядке.
Вот код :
getconbalanceAliases = "gc, getconbal" getconbalanceDesc = "Earn Conbalance! This command has a 30 second cooldown." @commands.cooldown(1, 30, commands.BucketType.user) @client.command(aliases=["gc","getconbal"]) async def getconbalance(ctx): await open_account(ctx.author) user = ctx.author users = await get_bank_data() earnings = random.randrange(101) await ctx.send(f'{ctx.author.mention} Got {earnings} coins!!') users[str(user.id)]["conbalance"] = earnings with open("conbalance.json",'w') as f: json.dump(users,f) @getconbalance.error async def getconbalance_error(ctx, error): if isinstance(error, commands.CommandOnCooldown): embed = discord.Embed(title = f"Slow it down bro", description = f"You look like a little baby when you beg.", color = 0xf461ff) now = datetime.now() current_time = now.strftime("%H:%M") embed.set_footer(text=f"Requested by {ctx.author} at {current_time}") await ctx.reply(embed=embed,mention_author=False)
Ответ №1:
Вам нужно использовать событие. На винтике это будет:
@commands.Cog.listener() async def on_command_error(self,ctx,error): if isinstance(error,commands.CommandOnCooldown):
Комментарии:
1. Я не использую cog. Можете ли вы показать мне, как это сделать без винтиков?
2. @MenIndo Для внешних винтиков мы используем
@client.event
3. @MenIndo, что означает, что код будет:
@client.event async def on_command_error(ctx, error): if isinstance(error, commands.CommandOnCooldown):