woohyunjng / discord.py-components

An unofficial third-party library of discord.py for discord components.
https://devkiki7000.gitbook.io/discord-components/
MIT License
128 stars 43 forks source link

A KeyError is raising when a button is clicked. [Bug] #68

Closed NomCustom closed 3 years ago

NomCustom commented 3 years ago

Bug Line

File client.py,line 762 in on_socket_response.

Excpected Action

What did you expect the module to do?

Actual Action

Ignoring exception in on_socket_response
Traceback (most recent call last):
  File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
 File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord_components/client.py", line 80, in on_socket_response
   if to_use["data"]["name"] in self.commands:
KeyError: "name"

Reproducing the action

import discord
from discord.ext import commands
import asyncio
import os
from discord_components import DiscordComponents, Button, ButtonStyle, InteractionType
import time
from mojang import MojangAPI

class Gamestats(commands.Cog, name="Game Stats"):
    """Les statistiques de tes jeux !"""
    def __init__(self, bot):
        self.bot = bot
        self.buttons = DiscordComponents(self.bot)

    @commands.command(name="gamestats", description="Les statistiques de jeux.")
    async def brawl(self, ctx):
        await ctx.send(
            "Quel jeux souhaitez vous sélectionner?",
            components=[
                Button(style=ButtonStyle.green, label="Mojang", id="buttonmj")
            ]
        )
        a = await self.buttons.wait_for_interact("button_click")
        if a.component.id == "buttonmj":
            await ctx.send("Entrez le nom d'un compte mojang")
            ma = await self.bot.wait_for("message", check=lambda m: m.channel == ctx.channel and m.author == ctx.author)
            uuid = MojangAPI.get_uuid(f"{ma}")
            if not uuid:
                await ctx.send("Ce compte n'existe pas !")
                pass
            else:
                await ctx.send(f"ID: {uuid}")

def setup(bot):
    bot.add_cog(Gamestats(bot))

Possible Solution

Change name to label I think? 🤔

Environment

Python 3.8.2

Check

kiki7000 commented 3 years ago

Use the GitHub version

pip install git+https://github.com/kiki7000/discord.py-components.git
NomCustom commented 3 years ago

Use the GitHub version

pip install git+https://github.com/kiki7000/discord.py-components.git

still not working

kiki7000 commented 3 years ago

I will close this because it is duplicate of #57