Help to remove cooldown when other (selfmade) error for an app command #9237
Answered
by
ika2kki
NavisGames
asked this question in
Q&A
-
Hello! i have an error handeler, now i want to reset the cooldown for an app command when my selfmade error (voteerror) stuff is getting called. class VoteError(app_commands.AppCommandError):
"""Exception that is raised when a user didnt vote."""
pass
@tree.error
async def on_app_command_error(
interaction: discord.Interaction, error: app_commands.AppCommandError
):
try:
if isinstance(error, app_commands.CommandOnCooldown):
embed = discord.Embed(
title="**Hey ganz ruhig!**",
description=f"du bist hier ganz schnell unterwegs! Versuche es in **{error.retry_after // (60 * 60):02.0f}:{(error.retry_after // 60) % 60:02.0f}:{error.retry_after % 60:02.0f}** erneut!",
color=0xFFC45F,
timestamp=datetime.now(),
)
embed.set_author(
name=f"{interaction.user}", icon_url=f"{interaction.user.avatar.url}"
)
await interaction.response.send_message(embed=embed, ephemeral=True)
elif isinstance(error, VoteError):
view = VoteLinkButton()
view.add_item(
discord.ui.Button(
label="top.gg",
style=discord.ButtonStyle.link,
url="https://top.gg/bot/1066416297392484494/vote",
)
)
embed = discord.Embed(
title="**Da funktioniert was nicht!**",
description=f"Du musst für den Bot auf **top.gg** (unten den Knopf klicken) voten um diesen Command auszuführen!",
color=0xFFC45F,
timestamp=datetime.now(),
)
embed.set_author(
name=f"{interaction.user}", icon_url=f"{interaction.user.avatar.url}"
)
# REMOVE COOLDOWN HERE!
await interaction.response.send_message(embed=embed, view=view, ephemeral=True)
else:
print(error)
except Exception as e:
print(e) i cant find a way resetting it.. |
Beta Was this translation helpful? Give feedback.
Answered by
ika2kki
Feb 15, 2023
Replies: 1 comment 1 reply
-
However, if @app_commands.checks.cooldown(1, 10) # Called last
@ensure_user_voted_for_bot() # Your own check
async def command(interaction: discord.Interaction):
... Here, the cooldown will only apply if the first check passes. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
NavisGames
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
app_commands
cooldowns are implemented differently toext.commands
, so currently there isn't a way to offer areset_cooldown
method.However, if
VoteError
is raised from a check, you can take advantage of the order checks are called so you don't need to reset it manually.Here, the cooldown will only apply if the first check passes.