Pycord-Development / pycord

Pycord is a modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python
https://docs.pycord.dev
MIT License
2.71k stars 458 forks source link

Error with buttons in a slash command #54

Closed LilJess13 closed 3 years ago

LilJess13 commented 3 years ago

Summary

Using buttons in a slash command produces a couple errors

Reproduction Steps

I created a slash command that contains a view with a couple buttons. I run the command and click on the buttons. The errors appear when the buttons are pressed. The code processes normally though as far as i can tell, but still leaves an error in the console.

Minimal Reproducible Code

bot = discord.Bot()

class TestButt(discord.ui.View):
    def __init__(self):
        super().__init__()

    @discord.ui.button(label = "Yes", style=discord.ButtonStyle.green)
    async def yes(self, button: discord.ui.Button, interaction = discord.Interaction):
        await interaction.response.send_message(content = "You picked yes", view = self)

    @discord.ui.button(label = "No", style=discord.ButtonStyle.red)
    async def no(self, button: discord.ui.Button, interaction = discord.Interaction):
        await interaction.response.send_message(content = "You picked no", view = self)

@bot.command(description = "Im a good slashy", guild_ids = [250507134876254208])
async def slashy(ctx):
    await ctx.reply(f"You like me?", view = TestButt())

Expected Results

Run without any errors

Actual Results

I get this error:

Ignoring exception in on_interaction
Traceback (most recent call last):
  File "C:\Users\Jesse\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\bot.py", line 249, in handle_interaction
    command = self.app_commands[interaction.data["id"]]
KeyError: 'id'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Jesse\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\client.py", line 351, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\Jesse\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\bot.py", line 355, in on_interaction
    await self.handle_interaction(interaction)
  File "C:\Users\Jesse\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\bot.py", line 252, in handle_interaction
    await interaction.response.send_message("I didn't recognize that command")
  File "C:\Users\Jesse\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\interactions.py", line 534, in send_message
    await adapter.create_interaction_response(
  File "C:\Users\Jesse\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\webhook\async_.py", line 189, in request
    raise NotFound(response, data)
discord.errors.NotFound: 404 Not Found (error code: 10062): Unknown interaction

Intents

I use all intents or Intents.all()

System Information

The command for the version doesnt work either apparently. But its pycord 2.0.0a

Checklist

Additional Context

No response

Dorukyum commented 3 years ago

We're aware of this, it happens because of the testing helpers in the code. Thanks for pointing it out once more

LilJess13 commented 3 years ago

Oh i must have missed that. Oops. Sorry!

Dorukyum commented 3 years ago

Fixed in #56