I'm making a button voting system. If the person has not yet voted, then +1 vote is added to the button.
Creating a button
class VotingManager(disnake.ui.View):
def __init__(self):
super().__init__(timeout=None)
@disnake.ui.button(label='0', style=disnake.ButtonStyle.gray, custom_id=f"voting-discord-like-{voting_discord_id}")
async def voting_like(self, button: disnake.ui.Button, interaction: disnake.MessageInteraction):
...
Later call to the button
elif interaction.data.custom_id.startswith("voting-discord-like"):
voting_id = interaction.data.custom_id.replace(
'voting-discord-like-', '')
connection = await aiosqlite.connect(settings['DATABASE'])
cursor = await connection.cursor()
await cursor.execute(
"SELECT voting_status FROM voting WHERE votingID = ?", (voting_id,))
voting_status = await cursor.fetchone()
print(voting_status[0])
if int(voting_status[0]) == 0:
await cursor.execute(
"UPDATE voting SET voting_status = ? WHERE votingID = ?", (True,voting_id,))
number = int(interaction.data.label)
interaction.data.label = str(number + 1)
await interaction.message.edit(view=self)
await connection.commit()
else:
error = disnake.Embed(
description=f'You have already voted for this idea. If you want to re-vote, then click on the reset button.', title='──⊰ ✜ ⊱ « :discord: Discord » ⊰ ✜ ⊱──', color=0xdfbe85)
await interaction.response.send_message(embed=error, ephemeral=True)
await connection.commit()
await connection.close()