pythondiscorddiscord.pyinteraction

interaction failed in discord.py


my buttons are working fine but its still giving me "interaction failed issue"

class StartButtons(discord.ui.View):
    def __init__(self, user_id, cog, channel):
        super().__init__()
        self.user_id = user_id
        self.cog = cog
        self.channel = channel

    @discord.ui.button(label='Hit', style=discord.ButtonStyle.primary, custom_id='hit')
    async def hit(self, button: discord.ui.Button, interaction: discord.Interaction):
        user_id = self.user_id
        await self.cog.hit(interaction, user_id, self.channel)

->** another class starts**

    async def hit(self, interaction, user_id, channel):
        if user_id not in self.players:
            await channel.send("You haven't started the game yet. Use `!start`.")
            return
         _some extra code, cant post cuz too much code_

i tried putting interaction.response.defer() in it, but still getting same issue


Solution

  • figured out, something minor took so much of my time:

    it's not

    async def hit(self, button: discord.ui.Button, interaction: discord.Interaction):
    

    the correct form is:

    async def hit(self, interaction: discord.Interaction, button: discord.ui.Button):
    

    And ofcourse add interaction.response.defer() or the other one, check documentation