From c6c1748f3e6fd416682206dd52530883bd8a32ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonathan=20M=C3=BCller?= Date: Tue, 26 Dec 2023 13:42:53 +0100 Subject: [PATCH] Added refresh command --- main.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/main.py b/main.py index ff6c93e..ae0bd5c 100644 --- a/main.py +++ b/main.py @@ -77,14 +77,19 @@ class CounterView(discord.ui.View): @discord.ui.button(label="+1", custom_id="count_plus_one", style=discord.ButtonStyle.primary) async def button_callback(self, button, interaction): with DBConnection() as cur: - cur.execute("SELECT value from settings WHERE name='message_id'") - message_id = cur.fetchone()[0] cur.execute("INSERT INTO member (user_id, count) VALUES (?, 1) ON DUPLICATE KEY UPDATE count=count + 1", (interaction.user.id, )) - channel = interaction.channel - message = await channel.fetch_message(int(message_id)) - await message.edit(embed=create_embed(interaction.guild), view=CounterView()) + await updatemessage(interaction.guild) await interaction.response.send_message("Ab ins Sparschwein damit!", ephemeral=True) +async def updatemessage(guild): + with DBConnection() as cur: + cur.execute("SELECT value from settings WHERE name='message_id'") + message_id = cur.fetchone()[0] + cur.execute("SELECT value from settings WHERE name='channel_id'") + channelid = cur.fetchone()[0] + channel = await guild.fetch_channel(int(channelid)) + message = await channel.fetch_message(int(message_id)) + await message.edit(embed=create_embed(guild), view=CounterView()) @bot.slash_command(name="set_channel", description="Setze den Channel, in dem der Zähler erstellt wird.") async def set_channel(ctx): @@ -95,6 +100,10 @@ async def set_channel(ctx): cur.execute("UPDATE settings SET VALUE = ? WHERE name = 'message_id'", (message.id,)) await ctx.respond(content="Done", ephemeral=True) +@bot.slash_command(name="update", description="Aktualisiere die Nachricht") +async def set_channel(ctx): + await updatemessage(ctx.guild) + await ctx.respond(content="Done", ephemeral=True) @bot.slash_command(name="reset_counter", description="Setze den Zähler auf Null.") async def reset_counter(ctx):