'Giveaway Bot with buttons discord.py
Hi this is my giveaway bot command, currently, I am using reactions in it but I want to replace it with buttons like someone clicks on the button then participates in the giveaway how can I do that? I have a rough idea we add a button first then we store the info of the user who clicked on a button in the database then after time over we fetch a random winner from that list but I am not sure how to exactly implement it I can add button but I am not able to figure out what next and how can I do that ,help will be really appreciated sorry if you find this question dumb or something
@app_commands.command(name = "giveaway" ,description="start a giveaway ")
async def gcreate(self, interaction: discord.Interaction, time:str , prize : str , donor:discord.Member,):
await interaction.response.defer(ephemeral=False, thinking=True)
timek = self.convert(time)
futuredate = datetime.utcnow() + timedelta(seconds=timek)
gembed = discord.Embed(color=0x55a7f7, title=f"**{prize}**", description=f"Click :tada: to enter!\n**Hosted By** : {interaction.user.mention}\n**Donated by** : {donor.mention}\n\n Coming soon", timestamp=futuredate)
msg = await interaction.followup.send(embed=gembed)
await msg.add_reaction("🎉")
await asyncio.sleep(timek)
message = await interaction.channel.fetch_message(msg.id)
for reaction in message.reactions:
if str(reaction.emoji) == "🎉":
users = [user async for user in reaction.users()]
winners = random.choice(users)
await interaction.followup.send(embed = discord.Embed(title="**Giveaway ended**" ,description=f"Congratulations {winners.mention} You have won the giveaway for {prize}"))
win =await msg.edit(embed = discord.Embed(color=0x55a7f7, title=f"**Giveaway ended**", description=f"Click :tada: to enter!\n**Hosted By** : {interaction.user.mention}\n**Donated by** : {donor.mention}\n\n Coming soon", timestamp=futuredate))
await winners.send(embed = discord.Embed(title="**Giveaway ended**" ,description=f"Congratulations {winners.mention} You have won the giveaway for {prize}"))
await interaction.user.send(embed=discord.Embed(title="**Giveaway ended**" , description=f"Your giveaway of {prize} is ended\n\nwinners :- {winners}"))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
