FIXED BUG DU HURENSOHN

This commit is contained in:
2023-11-28 20:30:00 +01:00
parent f49833dc74
commit e4c6598885

15
main.py
View File

@@ -12,7 +12,6 @@ with open('config.json') as user_file:
config = json.loads(user_file.read()) config = json.loads(user_file.read())
def connect_db(): def connect_db():
try: try:
conn = mariadb.connect( conn = mariadb.connect(
@@ -37,9 +36,12 @@ intents.members = True
bot = discord.Bot(intents = intents) bot = discord.Bot(intents = intents)
@bot.event @bot.event
async def on_ready(): 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!") print(f"{bot.user} is ready and online!")
conn = connect_db() conn = connect_db()
@@ -53,6 +55,7 @@ def get_count_recruits():
count = cur.fetchone()[0] count = cur.fetchone()[0]
return count return count
def build_option_list(): def build_option_list():
cur.execute("SELECT discord_id, nickname, recruit FROM recruits WHERE recruit=1") cur.execute("SELECT discord_id, nickname, recruit FROM recruits WHERE recruit=1")
options = [] options = []
@@ -73,6 +76,7 @@ class Yes_select(discord.ui.View):
max_values=get_count_recruits(), max_values=get_count_recruits(),
options=build_option_list() options=build_option_list()
) )
async def select_callback(self, select, interaction): # the function called when the user is done selecting options 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!") 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'") cur.execute("SELECT value FROM settings WHERE name='message_voting_yes'")
message = await channel.fetch_message(int(cur.fetchone()[0])) message = await channel.fetch_message(int(cur.fetchone()[0]))
conn.commit() 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!") print("Edited!")
@settings.command(description="Sendet die Nachricht zum Abstimmen in den aktuellen Channel.") @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 edit_yes_message()
await ctx.respond(f"Done.", ephemeral=True) await ctx.respond(f"Done.", ephemeral=True)
@bot.event @bot.event
async def on_member_update(previous, after): async def on_member_update(previous, after):
cur.execute("SELECT value FROM settings WHERE name='role_recruit'") cur.execute("SELECT value FROM settings WHERE name='role_recruit'")
@@ -183,4 +191,5 @@ async def on_member_update(previous, after):
break break
await edit_yes_message() await edit_yes_message()
bot.run(os.getenv('TOKEN')) # run the bot with the token bot.run(os.getenv('TOKEN')) # run the bot with the token