#Ticket system create ticket button not working
1 messages · Page 1 of 1 (latest)
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
Pycord, a maintained fork of discord.py, is a python wrapper for the Discord API - pycord/persistent.py at master · Pycord-Development/pycord
you can define exact thing in view and add it as persistent
full code
please
Learn all about implementing buttons in your Discord Bot using Pycord.
?tag oop
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.
that’s not how you create a button by subclassing
Here's the confirm example.
the buttons are created with decorators. your callback is within the init
also look
examples/views/confirm.py line 27
@discord.ui.button(label="Confirm", style=discord.ButtonStyle.green)```
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
should be lowercase @discord.ui.button
you have interaction.respond, change it to interaction.response.send_message()
I use a json to save stuff...
check syntax
my guy really be trying to elif without an if to begin with
read the error
function names should be unique
no, you named all your buttons myclass_callback
just change the names so they're all different
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)
yeah looks good now
such as pycharm
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?
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():
...
# Do this
async def callback1():
...
async def callback2():
...
they're still not on the same line
are u sure its not the indentation problem?
why do you check for custom_id when the callback under it will be assigned automatically without a check
yeah acctually u dont have to check for the custom_id
when the callback is linked to the button
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
IF your problem is solved please use /close
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.
You should have 3 view classes.
One with the create ticket button
One in the ticket
And one for the confirm closing of ticket
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.
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.