From ffec60ecc2baeda003912a79572ed67901a5abcc Mon Sep 17 00:00:00 2001 From: Kaaninchen <124433727+kaaninchen@users.noreply.github.com> Date: Fri, 17 Jul 2026 18:30:48 +0200 Subject: [PATCH] =?UTF-8?q?/Umstieg=20cooldown=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Discord hat diesen nervigen cooldown von 2 mal channel umbennen innerhalb von 10min. In dem cooldown hier ist es 1 mal pro 10 minuten, zur Sicherheit... --- main.py | 11 ++++++++--- src/commands.py | 2 ++ src/embeds.py | 1 - src/handlers.py | 8 +++++++- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index 638ffb6..c56b621 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ import discord import random -from discord.ext import tasks +import time +from discord.ext import tasks, commands from config import config from src.handlers import rename_vc from src.commands import setup_commands @@ -10,7 +11,7 @@ from src.data.status import discord_status bot = discord.Bot(intents=discord.Intents.all()) setup_commands(bot) -@tasks.loop(minutes=1) +@tasks.loop(minutes=5) async def change_status(): status = random.choice(discord_status) await bot.change_presence(activity=discord.Game(name=status)) @@ -24,7 +25,11 @@ async def on_ready(): @bot.event async def on_application_command_error(ctx, error): - embed = build_error_embed(f"Ein Fehler ist aufgetreten: {error}") + if isinstance(error, commands.CommandOnCooldown): + retry_timestamp = int(time.time() + error.retry_after) + embed = build_error_embed(f"Dein Umstieg ist erst da! (Discord Cooldown)") + else: + embed = build_error_embed(f"Ein Fehler ist aufgetreten: {error}") await ctx.respond(embed=embed) try: diff --git a/src/commands.py b/src/commands.py index 00806d8..153e618 100644 --- a/src/commands.py +++ b/src/commands.py @@ -1,9 +1,11 @@ import discord +from discord.ext import commands from src.handlers import rename_vc from src.embeds import build_info_embed, build_error_embed def setup_commands(bot: discord.Bot): @bot.slash_command(description="Steige in den nächsten Zug! Beachte das Discord Spam limit (2x in 10min)") + @commands.cooldown(1, 600, commands.BucketType.guild) async def umstieg(ctx): success = await rename_vc(bot) if not success: diff --git a/src/embeds.py b/src/embeds.py index 204a177..6fd21cf 100644 --- a/src/embeds.py +++ b/src/embeds.py @@ -57,7 +57,6 @@ def build_info_embed() -> discord.Embed | None: "Daten großzügig bereitgestellt von dbf.finalrewind.org" ) embed.set_footer(text=footer_text, icon_url="https://dbf.finalrewind.org/static/icons/icon-96x96.png") - return embed def build_error_embed(errormsg) -> discord.Embed: diff --git a/src/handlers.py b/src/handlers.py index f2f84c1..2d50431 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -1,4 +1,5 @@ import discord +import time from config import config from src.utils import random_connection @@ -25,6 +26,11 @@ async def rename_vc(bot: discord.Bot) -> bool: train = current['train'].split()[1] train_name = f"{train} nach {current['destination']}" - print(f"Umstieg: {train_name} von {current['station']} \nüber: {current['via']}") + print("-----------------------------------------") + current_time = time.strftime('%X') + print(f"{current_time}: Umstieg: {train_name} (Typ {train_type}) von {current['station']}") + print(f"{current_time}: Wenn hier keine Nachricht mehr kommt bin ich im Cooldown") await channel.edit(name=f"{config['formatting']}{train_name}",) + print(f"{current_time}: Name geändert!") + print("-----------------------------------------") return True \ No newline at end of file