#Ticket system create ticket button not working

1 messages · Page 1 of 1 (latest)

valid pelican
#

check it

velvet sparrow
#

The easiest way to check your code for possible errors is to put whole code from function in:

try:
     ...
except Exception as e:
     print(e)
#

btw isn't it easier to create view for it?

#

also I don't see any bot event for on_button_callback

#

you can define exact thing in view and add it as persistent

valid pelican
#

emmmm

#

use class

valid pelican
#

full code

#

please

golden estuary
#

?tag oop

coarse caveBOT
#

https://www.digitalocean.com/community/tutorials/understanding-class-and-instance-variables-in-python-3
https://docs.python.org/3/tutorial/classes.html

There's a difference between a class and an instance. Think of it like this:

  • A class is like a blueprint, or a concept. It defines what something should have, but it's not the same as actually having it.
  • An instance is the 'realized' version of the class, it contains everything that the class defines should be on it, but you can actually access and interact with these features.

Let's consider the Cat. We know a Cat has a name and an age, but Cat.age won't work, because Cat isn't an actual cat, it just represents the concept of a cat. It's like asking "What is the age of a cat?" - it doesn't make sense, because we need to have an actual cat.

mimi on the other hand is an instance of a Cat - it has everything a Cat should have. Maybe mimi was constructed, like mimi = Cat("Mimi", age=4), or maybe mimi was retrieved from somewhere else, like house.cats[0], but in any case, it has everything we need, and mimi.age will rightfully give us 4.

There are many situations in Object Oriented Programming where you will need an instance instead of a class to perform an operation properly (in fact, you almost always need an instance instead of a class), and these cases will usually be documented.
You should learn a good amount about Object Oriented Programming before working extensively with Pycord.

golden estuary
#

that’s not how you create a button by subclassing

warm summitBOT
#

Here's the confirm example.

golden estuary
#

the buttons are created with decorators. your callback is within the init

#

also look

warm summitBOT
#

examples/views/confirm.py line 27

@discord.ui.button(label="Confirm", style=discord.ButtonStyle.green)```
golden estuary
#

it uses decorators. idk what you did

#

oh mb, my phone’s loading things weird

#

so actually you should unindent all that blue stuff

#

because you create a button in the scope of a class, not in the init

#

unindent

#

yup

brazen cliff
#

should be lowercase @discord.ui.button

earnest bear
#

you have interaction.respond, change it to interaction.response.send_message()

golden estuary
#

it’s interaction.user

#

I’m not familiar with sql

earnest bear
#

I use a json to save stuff...

golden estuary
#

check syntax

mighty nexus
#

my guy really be trying to elif without an if to begin with

earnest bear
#

read the error

brazen cliff
#

function names should be unique

#

no, you named all your buttons myclass_callback

#

just change the names so they're all different

lilac vault
#

i want to say 1 thing, by

SELECT * FROM PrivateTicketSupport WHERE guild_id= AND user_id=;

do

await cursor.execute("SELECT * FROM PrivateTicketSupport WHERE guild_id=? AND user_id=?;", (ctx,guild.id, ctx.author.id))

the second one is safer

#

something with sql injection

#

is the second safer

#

geine probleme

#

if you want

#

if its getting inactive then u can automatic close

#

for me(its a littlebit sketchy to see the code)

golden estuary
#

consider using an actual IDE

#

an actual IDE would catch most of these errors

lilac vault
#

yeah looks good now

lilac vault
#

vscode(idfk if that counts as an ide)

#

so the buttons in MyView is not working?

#

hm is it possible that there is no button with the custom id ticket_close?

#

stupid solution but it can be because the name of the function is myhoya_callback

#

change it to callback?

mighty nexus
#

it's because of your indentation. use an IDE please

#

as you can see, you're having a button within another function of another button. you're nesting everything

#

you want them at the same indentation

#

don't do this:

async def callback1():
    ...

        async def callback2():
            ...
lilac vault
#

Yeah

#

Forgot to ask if u had errors

mighty nexus
#

# Do this
async def callback1():
    ...

async def callback2():
    ...
#

they're still not on the same line

lilac vault
#

are u sure its not the indentation problem?

mighty nexus
#

why do you check for custom_id when the callback under it will be assigned automatically without a check

lilac vault
#

when the callback is linked to the button

mighty nexus
#

what

#

do you not want them to appear there?

#

make another class and assign the two separate buttons then edit the original buttons to be that if the new class

#

that is one class

#

which of these callbacks do you want the two buttons to appear at?

#

yes but which callback of those two is that

#

you have multiple callbacks in that

#

no but im asking WHICH ONE do u want to trigger it

#

you have three callbacks in your MyView

#

im gonna be honest, your code is really messy

#

do you want a separate message to be shown when you interact with the button or do you want the same one to be edited?

#

in that case just

#

in your class MyView, add the following

def __init__(self):
    self.new_buttons = discord.ui.View()
    self.new_buttons.add_item(Button(label="whatever you want") # first button
    self.new_buttons.add_item(Button(label="whatever you want2") # second button
    self.new_buttons.children[0].callback = your_name_of_callback_for_first_button
    self.new_buttons.children[1].callback = your_name_of_callback_for_second_button

``` then add your callbacks in the MyView class, NOT under a @discord.ui.button decorator.
#

don't delete whatever you have

#

just add it

#

and then in the callback that you want to send those buttons, you add:

interaction.response.send_message(content="your content", view=self.new_buttons)
#

what is your full command? do you do a command first to prompt a modal and then after the modal this

#

shows up

#

or does that show up before and it prompts the modal?

#

are you not working with a modal

#

so what do you want the button to do then

#

ok so u want a ticket system. do you have a command that shows that embed and buttons?

#

just dm me and ill rewrite it for u

fossil fossil
#

IF your problem is solved please use /close

fossil fossil
#

Can you make a quick summary of your problem?
What is still broken?

#

Can you show the current code for the event that sends the embed in the image above

#

Specifically I want to see the create ticket button callback

#

Is this the updated view code?
If not please send the updated code

#

So one thing I notice is that the ticket_yes button is being created twice. Once in the init and once in the decorater.
Personally I would make another class instead of trying to create the view in the init of a different view.

fossil fossil
#

You should have 3 view classes.
One with the create ticket button
One in the ticket
And one for the confirm closing of ticket

fossil fossil
#

MyClass is persisten i assume.
You send MyView with the ticket message. (It looks right in the image.)
And you should send a message with the last class in the callback of the close ticket button.

fossil fossil
#

Yes that is how it should be. What version of pycord are you on? (pip list)
No errors?
Can you upload your code for tickets somewhere (or send as a file) so I can test it sometime later.