#My buttons appear but it says interaction failed

1 messages · Page 1 of 1 (latest)

blissful forge
#

Interaction.respond? confused2

patent marten
#

Can I just get rid of that?

blissful forge
#

I sincerely don't understand your view

blissful forge
#

Why are you waiting for button click

#

Buttons have callbacks

#

Use callbackz

patent marten
#

Because I use that info to be sent to a different channel

blissful forge
#

What does that even have to do with doing callbacks lmao

#

You can still process and send data to different channels

patent marten
#

I just have to use a callback

blissful forge
robust onyx
#

"button_click" isn't a real event, so this will never work.

patent marten
#

Ohh ok

patent marten
robust onyx
patent marten
#

@robust onyx so would i just change the code to a class pretty much

robust onyx
#

it would be easier yes

patent marten
#

pretty much keep the same format though?

robust onyx
#

if you use the latter example, for the most part you should be able to

patent marten
#
        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

robust onyx
# patent marten if I have mutliple buttons how would I assign them to a variable like league_for...

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...")

patent marten
#

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()

robust onyx
#

well you do need to either respond or defer the button interaction

patent marten
#

defer just means no response right?

#

so just await interaction.defer()

robust onyx
#

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.

patent marten
#

what if i want it to be sent in an embed tho?

#

the value of the button

#

@robust onyx

robust onyx
#

wdym

patent marten
#

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

robust onyx
#

that's exactly what i showed above...

#
  1. you have to respond, even if it's just a defer
#
  1. the entire value example above is literally what you want, you assign a value via a self variable then you can access it later as demonstrated
patent marten
#

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

robust onyx
#

it's all good

patent marten
#

well at least coding discord bots

robust onyx
#

you just add another decorator function with another name

#

no need for another class

patent marten
#

ohhhh

#

just set both self.values() = true?

robust onyx
#

self.value is just an example

#

it's whatever you want that button to represent

patent marten
#

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.

patent marten
#

@robust onyx

glass forge
#

hmm full error?

patent marten
#

Hold on not at my computer

patent marten
#

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

patent marten
#

@robust onyx ???

bleak token
#

If you are still experiencing the problem please repost. With the up to date information.