#how do I pass on_interaction(interaction) on certain interactions

1 messages · Page 1 of 1 (latest)

stiff geyser
#

hey guys I have a bot where I want the buttons to be persistent and I want to check when the button is clicked do something,

but with @bot.event async def on_interaction(interaction): if interaction.custom_id == "feedback": print ("do something")
it seems like its taking on every interaction that means the slash commands to ,

How Do I pass and let the normal command work

async def menu(ctx):
    view = MyView()
    embed=discord.Embed(title="Welcome", description="This is the menu for Contentmatch", color=0xff0000)
    embed.set_author(name="ContentMatch")
    embed.add_field(name="/menu", value="For A Menu Of Items", inline=False)
    embed.add_field(name="/account", value="Get Account Info ", inline=True)
    embed.add_field(name="/post", value="To Post Content", inline=True)
    embed.add_field(name="/watch", value="Get A Random Video Sent To You", inline=True)
    await ctx.send(embed=embed,view=view)```
#

like when an application command happends just do nothing and return what the original

ancient wolf
#

Im sure it's better if you make the button a separate subclass with its own callback

#

and then add it to the bots persistent views

stiff geyser
#

but if the bot stops

#

and restarts the buttons dont work

ancient wolf
#

thats why you add the persistent views in the bot's on_ready()

brittle spokeBOT
#

Here's the persistent example.

stiff geyser
#

no way its that easy

ancient wolf
#

here's an example for persistent views you can see and adapt

stiff geyser
#
    def __init__(self):
        super().__init__(timeout=None)```
#

i already have done that

ancient wolf
#

alright, so add the button to that view

#

give it a callback and add it to the bots on_ready

stiff geyser
#
    def __init__(self):
        super().__init__(timeout=None)
   
    @discord.ui.button(label="Post", style=discord.ButtonStyle.primary,custom_id="post")
    async def button_callback(self,button,interaction):
        await interaction.response.send_modal(MyModal(title = "What Are we going To Post Today {{name}}"))
#

buttons in the view already

#

is this correct?

ancient wolf
#

should be

stiff geyser
#

i have had that but doesnt work

#

@ancient wolf u open for commision?

ancient wolf
#

it's really not that hard

#

did you add the view to the bots on_ready?

stiff geyser
#

why would I add the view to the on_ready?

ancient wolf
#

so it's a persistent view

#

like how the example shows

#

what it does is that every time the bot starts it adds the view

#

so it can still work after a restart

stiff geyser
#

Ohh how do i do that?

#

view = MyView()

ancient wolf
#
@bot.event()
async def on_ready(self):
    self.add_view(MyView())
stiff geyser
#

@ancient wolf i appreciate the help but not working

#
    await coro(*args, **kwargs)
TypeError: on_ready() missing 1 required positional argument: 'self'```
#
@bot.event
async def on_ready(self):
    self.add_view(MyView())```
ancient wolf
#

ohh take off the self

#

self is only for if its in a class

stiff geyser
#

doesnt work

ancient wolf
#

let me fix the code for you

#

is the bot in the main file?

stiff geyser
#

yes

ancient wolf
#
@bot.event()
async def on_ready():
    bot.add_view(MyView())
stiff geyser
#

ohhh

ancient wolf
#

since it's not in a bot subclass it doesn't use self

stiff geyser
#

TYYYYYYYYYY

#

YOU'RE RAISED AS A GREAT PERSON

#

mwahh

#

i think i found a picture of @ancient wolf

ancient wolf
#

no problem brother