diff --git a/main.py b/main.py index e444c76..db29b21 100644 --- a/main.py +++ b/main.py @@ -12,7 +12,6 @@ with open('config.json') as user_file: config = json.loads(user_file.read()) - def connect_db(): try: conn = mariadb.connect( @@ -37,9 +36,12 @@ intents.members = True bot = discord.Bot(intents = intents) + @bot.event async def on_ready(): - bot.add_view(Yes_select()) + global select + select = Yes_select() + bot.add_view(select) print(f"{bot.user} is ready and online!") conn = connect_db() @@ -53,6 +55,7 @@ def get_count_recruits(): count = cur.fetchone()[0] return count + def build_option_list(): cur.execute("SELECT discord_id, nickname, recruit FROM recruits WHERE recruit=1") options = [] @@ -73,6 +76,7 @@ class Yes_select(discord.ui.View): max_values=get_count_recruits(), options=build_option_list() ) + async def select_callback(self, select, interaction): # the function called when the user is done selecting options await interaction.response.send_message(f"Awesome! I like {select.values[0]} too!") @@ -98,7 +102,10 @@ async def edit_yes_message(): cur.execute("SELECT value FROM settings WHERE name='message_voting_yes'") message = await channel.fetch_message(int(cur.fetchone()[0])) conn.commit() - result = await message.edit(embed=create_yes_embed(), view=Yes_select()) + global select + #result = await message.edit(embed=create_yes_embed(), view=Yes_select()) + select.children[0].options = build_option_list() + await message.edit(embed=create_yes_embed(), view=select) print("Edited!") @settings.command(description="Sendet die Nachricht zum Abstimmen in den aktuellen Channel.") @@ -162,6 +169,7 @@ async def refresh(ctx): await edit_yes_message() await ctx.respond(f"Done.", ephemeral=True) + @bot.event async def on_member_update(previous, after): cur.execute("SELECT value FROM settings WHERE name='role_recruit'") @@ -183,4 +191,5 @@ async def on_member_update(previous, after): break await edit_yes_message() + bot.run(os.getenv('TOKEN')) # run the bot with the token