#๐Ÿ”’ buttons in dpy

60 messages ยท Page 1 of 1 (latest)

marsh robin
#

this is my code:

class ConfirmOrderMenu(discord.ui.View):
    def __init__(self):
        super().__init__()
        self.value = None
    
    @discord.ui.button(label = "Confirm Order", style = discord.ButtonStyle.green)
    async def confirm(self, button: discord.ui.Button, interaction: discord.Interaction):
        print("success")
        self.value = "confirm"
        self.stop
    
    @discord.ui.button(label = "Cancel Order", style = discord.ButtonStyle.red)
    async def cancel(self, button: discord.ui.Button, interaction: discord.Interaction):
        print("canceled")
        self.value = "cancel"
        self.stop

@client.tree.command(name = "bolt")
async def bolt(interaction: discord.Interaction):

    menu = ConfirmOrderMenu()
    temp_channel = client.get_channel(temp_channel.id)
    await temp_channel.send(f"<@{interaction.user.id}>")
    await temp_channel.send(embed=confirm_order_embed, view=menu)

    await menu.wait()

    if menu.value == "confirm":
        print("ok")

im trying to get it to print ok

rich estuaryBOT
#

@marsh robin

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

marsh robin
#

one second editing msg

lunar prawn
rich estuaryBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

lunar prawn
#

put it in here

marsh robin
#

okay

lunar prawn
#

lemme boot up my laptop rq

marsh robin
#

aight

lunar prawn
#

ok i'm on it

marsh robin
#

last resort chatgpt

#

thats what it gave me

lunar prawn
# marsh robin this is my code: ```py class ConfirmOrderMenu(discord.ui.View): def __init_...

this is not how you want to make a confirmation view. the issues are:

  1. the parameters are the wrong way around
  2. .stop is mentioned, not called
  3. it would be easier to set .value to a boolean instead of a string
  4. (optional) use shortened statements through imports:
# Do this
from discord.ui import button, View

class MyView(View):
    @button(...)
    async def ...(...):
        ...

# Instead of this
import discord

class MyView(discord.ui.View):
    @discord.ui.button(...)
    async def ...(...):
        ...
lunar prawn
lunar prawn
#

!rule 10

rich estuaryBOT
#

10. Do not copy and paste answers from ChatGPT or similar AI tools.

lunar prawn
#

there's a reason we have this rule

marsh robin
lunar prawn
#

because AI responses are often incorrect

marsh robin
#

in my case i didnt paste an answer though

lunar prawn
#

they're unreliable at best

marsh robin
#

true

lunar prawn
#

and linking it to why you shouldn't use AI tools

lunar prawn
marsh robin
#

okay ill change it

lunar prawn
lunar prawn
marsh robin
#

thanks for pointing them out

#

i changed them, but still how do i get it to print ok?

lunar prawn
marsh robin
#
class ConfirmOrderMenu(View):
    def __init__(self):
        super().__init__()
        self.value = None
    
    @button(label = "Confirm Order", style = discord.ButtonStyle.green)
    async def confirm(self, button: discord.ui.Button, interaction: discord.Interaction):
        print("success")
        self.value = "confirm"
        self.stop
    
    @button(label = "Cancel Order", style = discord.ButtonStyle.red)
    async def cancel(self, button: discord.ui.Button, interaction: discord.Interaction):
        print("canceled")
        self.value = "cancel"
        self.stop


@client.tree.command(name = "bolt")
async def bolt(interaction: discord.Interaction):

    menu = ConfirmOrderMenu()
    temp_channel = client.get_channel(temp_channel.id)
    await temp_channel.send(interaction.user.mention)
    await temp_channel.send(embed=confirm_order_embed, view=menu)

    await menu.wait()

    if menu.value == "confirm":

        print("ok")
#

its not the entire bolt command but i dont think it makes a difference wether i send the entire thing or not

lunar prawn
#

i listed 5 other issues

marsh robin
#

sorry but which exactly

marsh robin
#

im not sure if i even need it

lunar prawn
#

!e ```py
def f():
print(5)

f
f()

rich estuaryBOT
lunar prawn
#

see how it only prints once?

marsh robin
#

ohhhhh

#

yes i know what you mean

lunar prawn
#

!e ```py
def f():
print(5)

f()

rich estuaryBOT
lunar prawn
#

that's how you get a function to run

marsh robin
#

i got it working

#

tysm

lunar prawn
marsh robin
# lunar prawn lemme see the code
class ConfirmOrderMenu(View):
    def __init__(self):
        super().__init__()
        self.value = None
    
    @button(label = "Confirm Order", style = discord.ButtonStyle.green)
    async def confirm(self, button: discord.ui.Button, interaction: discord.Interaction):
        self.value = "confirm"
        self.stop()
    
    @button(label = "Cancel Order", style = discord.ButtonStyle.red)
    async def cancel(self, button: discord.ui.Button, interaction: discord.Interaction):
        self.value = "cancel"
        self.stop()


@client.tree.command(name = "bolt")
async def bolt(interaction: discord.Interaction):

    menu = ConfirmOrderMenu()
    temp_channel = client.get_channel(temp_channel.id)
    confirm_order_msg = await temp_channel.send(interaction.user.mention, embed=confirm_order_embed, view=menu)

    await menu.wait()

    if menu.value == "confirm":

        print("ok")
lunar prawn
#

did you read what i said?

rich estuaryBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.