Bug Line
Ignoring exception in command button:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 85, in wrapped
ret = await coro(*args, **kwargs)
File "main.py", line 29, in button
await ctx.send("Buttons!", components=[Button(label="Button", custom_id="button1")])
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord_slash/dpy_overrides.py", line 323, in send_override
return await send(channel, *args, **kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord_slash/dpy_overrides.py", line 300, in send
data = await state.http.send_message(
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/http.py", line 156, in request
kwargs['data'] = utils.to_json(kwargs.pop('json'))
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/utils.py", line 328, in to_json
return json.dumps(obj, separators=(',', ':'), ensure_ascii=True)
File "/usr/lib/python3.8/json/__init__.py", line 234, in dumps
return cls(
File "/usr/lib/python3.8/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/lib/python3.8/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/usr/lib/python3.8/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Button is not JSON serializable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/bot.py", line 939, in invoke
await ctx.command.invoke(ctx)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 863, in invoke
await injected(*ctx.args, **ctx.kwargs)
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/discord/ext/commands/core.py", line 94, in wrapped
raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: Object of type Button is not JSON serializable
Expected Action
What did you expect the module to do?
Send a message with a button when the button command is executed
Actual Action
What actually happened?
It throwed an discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: Object of type Button is not JSON serializable exception
Reproducing the action
How could you reproduce the action?
from discord_components import DiscordComponents,InteractionEventType,ComponentsBot,Button
TOKEN="bot token"
client=ComponentsBot(command_prefix="?",help_command=None)
@client.event
async def on_ready():
print("ready")
@client.command()
async def button(ctx):
await ctx.send("Buttons!", components=[Button(label="Button", custom_id="button1")])
interaction = await client.wait_for(
"button_click", check=lambda inter: inter.custom_id == "button1"
)
await interaction.send(content="Button Clicked")
client.run(TOKEN)
Possible Solution
How do you think you can fix this bug?
Make the button class JSON serializable.
Environment
What is the version of the python?
python 3.8.3
Check
- [x] Are you using the newest version?
- [ ] Is this bug related to security issues?
bug