#My buttons appear but it says interaction failed
1 messages · Page 1 of 1 (latest)
Can I just get rid of that?
I sincerely don't understand your view
You tell me? What does it even do? That method doesn't exist
Why are you waiting for button click
Buttons have callbacks
Use callbackz
Because I use that info to be sent to a different channel
What does that even have to do with doing callbacks lmao
You can still process and send data to different channels
I just have to use a callback
Learn all about implementing buttons in your Discord Bot using Pycord.
"button_click" isn't a real event, so this will never work.
Ohh ok
Do I have to use a class to callback the button to send the information?
yes, i would recommend referring to examples:
- https://github.com/Pycord-Development/pycord/blob/master/examples/views/counter.py if you want logic to continue in the callback
- https://github.com/Pycord-Development/pycord/blob/master/examples/views/confirm.py If you want to return back to your original function after using the view
@robust onyx so would i just change the code to a class pretty much
it would be easier yes
pretty much keep the same format though?
if you use the latter example, for the most part you should be able to
title=f"Submission from {ctx.author.display_name}",
description=f"**League:** {league} ({league_format}) \n**Region:** {region} \n**Date:** {date}/23 \n**Time:** {time_str} \n**Matchup:** {team1} vs {team2}" \
+ (f"\n[**Caster link**]({caster})" if caster else ""),
color=0xFFFFFF
).set_author(
name=ctx.author.name,
icon_url=ctx.author.display_avatar
))
await ctx.respond(embed=discord.Embed(
title="Stryker Bot - Match Info",
description="Submission sent!",
color=0xFFFFFF
), ephemeral=True)```
so right now i need the league_format to be a button they clicked
if I have mutliple buttons how would I assign them to a variable like league_format
would I just make like league_format = to my class ex. Confirm()
@robust onyx
from the 2nd example: py @discord.ui.button(label="Confirm", style=discord.ButtonStyle.green) async def confirm_callback( self, button: discord.ui.Button, interaction: discord.Interaction ): await interaction.response.send_message("Confirming", ephemeral=True) self.value = True # This is what you want self.stop() the self.value = ... part is what you want, as that's what they use back in the command ```py
view = Confirm()
await ctx.send("Do you want to continue?", view=view)
# Wait for the View to stop listening for input...
await view.wait()
if view.value is None: # view.value was set in the callback above
print("Timed out...")
i dont necessarily need the await interaction.response.send_message
or the await ctx.send("Do you want to continue?", view=view)
# Wait for the View to stop listening for input...
await view.wait()
well you do need to either respond or defer the button interaction
with invisible=True yes
view.wait is exactly what you need if you want to keep doing it in the command
but if you're fine with continuing in the callback, the first example makes more sense.
what if i want it to be sent in an embed tho?
the value of the button
@robust onyx
wdym
i dont want it so that when you just click the button, it sends something back
i want it so that the button is stored as like a variable or something and sent in a different message
that's exactly what i showed above...
- you have to respond, even if it's just a
defer
- the entire
valueexample above is literally what you want, you assign a value via aselfvariable then you can access it later as demonstrated
so would i need 2 classes if i wanted two buttons?
sorry man, new to coding and trying to learn lol
thanks for being patient with me
it's all good
well at least coding discord bots
the core example that we're using shows you how to have multiple buttons https://github.com/Pycord-Development/pycord/blob/master/examples/views/confirm.py
you just add another decorator function with another name
no need for another class
ok everything has just like clocked into my brain lol
gonna switch a few things up and show you to see if everything looks right
def __init__(self):
super().__init__()
self.value = None
@discord.ui.button(label="2v2", style=discord.ButtonStyle.primary)
async def league1(
self, button: discord.ui.Button, interaction: discord.Interaction
):
self.value = True
self.stop()
@discord.ui.button(label="3v3", style=discord.ButtonStyle.primary)
async def league2(
self, button: discord.ui.Button, interaction: discord.Interaction
):
self.value = True
self.stop()```
here's my class @robust onyx
view = Confirm()
await ctx.respond(embed=discord.Embed(
title="League Format",
description="What format does this league use?",
color=0xFFFFFF
), view=view, ephemeral=True)
return```
then this is the embed i have sent
tried it but got this error
TypeError: Callback must be a coroutine.
@robust onyx
hmm full error?
Hold on not at my computer
Traceback (most recent call last):
File "c:/Users/lukes/OneDrive/Desktop/Test Bot/stryker.py", line 129, in <module>
class Confirm(discord.ui.View):
File "C:\Users\lukes\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\bot.py", line 930, in decorator
result = command(**kwargs)(func)
File "C:\Users\lukes\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\commands\core.py", line 1788, in decorator
return cls(func, **attrs)
File "C:\Users\lukes\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\discord\commands\core.py", line 668, in init
raise TypeError("Callback must be a coroutine.")
TypeError: Callback must be a coroutine.
thats the full error
@glass forge
@robust onyx ???
If you are still experiencing the problem please repost. With the up to date information.
