From ae563158b7fe95d9ae000f78b1d4f8cc171d5b51 Mon Sep 17 00:00:00 2001 From: supopur Date: Sat, 11 Mar 2023 10:15:53 +0100 Subject: [PATCH] Made sure that there is ctx.defer() so we no longer get Unknown interaction errors. --- cogs/example.py | 10 +++++++++- main.py | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cogs/example.py b/cogs/example.py index 2e7b991..6a0f125 100644 --- a/cogs/example.py +++ b/cogs/example.py @@ -13,11 +13,19 @@ class Greetings(commands.Cog): @commands.slash_command(guild_ids=["823188238260633600"]) async def uptime(self, ctx): + #Extends the 3s limit to reply so we dont get a unknown interation error. + ctx.defer() + #References the api api = self.bot.api + #Logs something using the api api.logger("inf", "example.py: Getting uptime...") + + #Gets the seconds of how long the root of the bot is runnig uptime = api.uptime() + #Converts it into a HH:MM:SS format thats more readable. Also the .split makes sure that there are no ms uptime = str(datetime.timedelta(seconds=uptime)).split(".")[0] - await ctx.respond(f"The uptime in H:MM:SS format: {uptime}") + #Sends a follow up + await ctx.followup.send(f"The uptime in H:MM:SS format: {uptime}") def setup(bot): bot.add_cog(Greetings(bot)) diff --git a/main.py b/main.py index ecce090..2f62fa0 100644 --- a/main.py +++ b/main.py @@ -162,6 +162,7 @@ async def on_ready(): @bot.slash_command(guild_ids=["823188238260633600"]) async def stop(ctx): + ctx.defer() if ctx.author.guild_permissions.administrator: print("Terminating the bot...") try: