From fcfd10d5cdc6d1766906ec58460f57fdad598dbd Mon Sep 17 00:00:00 2001 From: BigGamerGary Date: Mon, 21 Nov 2022 23:11:51 +1000 Subject: [PATCH] Added a second button Only one button can be pressed --- Acronymbot.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/Acronymbot.py b/Acronymbot.py index 5d92dfe..069d021 100644 --- a/Acronymbot.py +++ b/Acronymbot.py @@ -1,8 +1,5 @@ import discord - from discord import app_commands -from discord.app_commands.errors import CommandInvokeError - botIntents = discord.Intents.all() @@ -15,12 +12,12 @@ async def on_ready(): await tree.sync() print('Itsa me Mario!') -@tree.command(name="gibme", description="Lmao") +@tree.command(description="Lmao") async def test(interaction:discord.Interaction): print(f"{interaction.user} used command! Woohoo!") try: await interaction.response.send_message("Pay $5 for a Mario Moment", view=Buttons()) - except CommandInvokeError: + except discord.app_commands.errors.CommandInvokeError: print("Uh oh! It failed!") class Buttons(discord.ui.View): @@ -28,11 +25,22 @@ class Buttons(discord.ui.View): super().__init__(timeout=timeout) @discord.ui.button(label="Pay $5", style=discord.ButtonStyle.green) - async def button(self, interaction: discord.Interaction, button: discord.ui.Button): - print(f"{interaction.user} pressed the button") + async def green_button(self, interaction: discord.Interaction, button: discord.ui.Button): + print(f"{interaction.user} pressed the green button") button.disabled = True button.label = "No Refunds!" - await interaction.response.edit_message(content=f"Gary is a Capitalist", view=self) + for child in self.children: + child.disabled = True + await interaction.response.edit_message(content=f"Mario Moment Achieved", view=self) + + @discord.ui.button(label="Punch AcryBot", style=discord.ButtonStyle.red) + async def red_button(self, interaction: discord.Interaction, button: discord.ui.Button): + print(f"{interaction.user} pressed the red button") + button.disabled = True + button.label = f"fuck you {interaction.user}" + for child in self.children: + child.disabled = True + await interaction.response.edit_message(content=f"Ouch!", view=self)