From db85eb9e1f6aed92f2da5a4620b809806034542e Mon Sep 17 00:00:00 2001 From: LuminatiHD Date: Thu, 17 Feb 2022 15:36:00 +0100 Subject: [PATCH] Poll buttons now terminate after the given time has passed --- Buttons.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Buttons.py b/Buttons.py index b696a9c..26bab9e 100644 --- a/Buttons.py +++ b/Buttons.py @@ -713,25 +713,30 @@ async def goback(self, button: nextcord.Button, interaction: nextcord.Interactio class Poll_Button(nextcord.ui.Button): - def __init__(self, label, view_obj): + def __init__(self, label, view_obj, duration): super().__init__() self.label = label + self.over = datetime.now()+timedelta(seconds=duration) self.style = nextcord.ButtonStyle.blurple self.view_obj = view_obj async def callback(self, interaction: nextcord.Interaction): - if interaction.user.id in self.view_obj.voters.keys(): + if interaction.user.id in self.view_obj.voters.keys() \ + and self.view_obj.voters[interaction.user.id] != self.label: await interaction.response.send_message("Dein Vote wurde geƤndert", ephemeral=True) self.view_obj.voters[interaction.user.id] = self.label + if datetime.now()> self.over: + self.view_obj.stop() + class Poll_ViewObj(nextcord.ui.View): def __init__(self, options, duration): super().__init__(timeout=duration) self.voters = {} for opt in options: - self.add_item(Poll_Button(label=opt, view_obj=self)) + self.add_item(Poll_Button(label=opt, view_obj=self, duration=duration)) class Vote_btns(nextcord.ui.View):