New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: component sending/editing with context #396
Conversation
Since you've implemented mutable tables to the |
You mean like |
I think there may be an issue for checking if |
Yep it works, used |
interactions/context.py
Outdated
] | ||
elif isinstance(components, (Button, SelectMenu)): | ||
if isinstance(components, SelectMenu): | ||
components._json["options"] = [option._json for option in components.options] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
components._json["options"]
should not need to be overwritten as of the latest unstable
commit, since we have a recursive generator being applied.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed lines 257 and 258, and the respective lines in edit()
as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yeah @goverfl0w, this is why I put it in the first place:
ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-16' coro=<my_command() done, defined at c:\Users\hi\Desktop\Coding\Python\discord-interactions v4\main.py:31> exception=TypeError('Object of type SelectOption is not JSON serializable')>
Traceback (most recent call last):
File "c:\Users\hi\Desktop\Coding\Python\discord-interactions v4\main.py", line 143, in my_command
await ctx.send("b", components=select)
File "C:\Users\hi\AppData\Local\Programs\Python\Python39\lib\site-packages\interactions\context.py", line 343, in send
await func()
File "C:\Users\hi\AppData\Local\Programs\Python\Python39\lib\site-packages\interactions\context.py", line 336, in func
await self.client.create_interaction_response(
File "C:\Users\hi\AppData\Local\Programs\Python\Python39\lib\site-packages\interactions\api\http.py", line 2061, in create_interaction_response
return await self._req.request(
File "C:\Users\hi\AppData\Local\Programs\Python\Python39\lib\site-packages\interactions\api\http.py", line 200, in request
async with self.session.request(
File "C:\Users\hi\AppData\Local\Programs\Python\Python39\lib\site-packages\aiohttp\client.py", line 1117, in __aenter__
self._resp = await self._coro
File "C:\Users\hi\AppData\Local\Programs\Python\Python39\lib\site-packages\aiohttp\client.py", line 390, in _request
data = payload.JsonPayload(json, dumps=self._json_serialize)
File "C:\Users\hi\AppData\Local\Programs\Python\Python39\lib\site-packages\aiohttp\payload.py", line 381, in __init__
dumps(value).encode(encoding),
File "C:\Users\hi\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "C:\Users\hi\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "C:\Users\hi\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "C:\Users\hi\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type SelectOption is not JSON serializable
I'm gonna revert the commit and keep the lines and try again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed, this still has not been fixed:
components: Optional[
Union[Union[ActionRow, Button, SelectMenu], List[Union[ActionRow, Button, SelectMenu]]]
]
You have Union
repeating twice.
I have resolved the changes, I will test them now |
About
This pull request is about fixing component sending/editing with context, which lets you send/edit components using the context (
ctx
) properly.Specifically
await ctx.send(...)
andawait ctx.edit(...)
.In addition to fixing component sending/editing, I have also filled in missing ways to send/edit components:
Sending/editing one ActionRow
Here is a sample code example where you can send and edit one ActionRow:
Result:
Sending/editing individual components
Sample code:
Result:
Sending/editing multiple ActionRows
Sample code:
Result:
Sending/editing with lists
Sample code:
Result:
Finally, removing components
When editing, the components stay if
components=None
, but anything else that is not a list of action rows, a list of components, component, action row, or a list of a list of components (example:[]
), the components will be removed from the message.Sample code:
Result:
Please review this code and tell me if I have done anything incorrectly.
Checklist
pre-commit
to format and lint the change(s) made.3.8.6
and higher.