#Container Json in Container Item

1 messages · Page 1 of 1 (latest)

distant dome
#

I have a container and convert it into a dict using container.to_component_dict() so that I can save it in the database. But now I have to somehow pack the json back into a container item when selecting so that I can send it. Unfortunately, I have not found a solution for this.

sterile ridge
#

@simple pivot idk if this is exoected

distant dome
#

Wenn ich das Json versuche kommt dieser Fehler

Traceback (most recent call last):
  File "C:\Users\basti\BastiGame\Development\DevHQ\InternalBot\.venv\Lib\site-packages\discord\ui\modal.py", line 340, in dispatch
    await value.callback(interaction)
  File "C:\Users\basti\BastiGame\Development\DevHQ\InternalBot\cogs\experiments.py", line 102, in callback
    view = discord.ui.View(d, timeout=None)
  File "C:\Users\basti\BastiGame\Development\DevHQ\InternalBot\.venv\Lib\site-packages\ezcord\components.py", line 134, in __init__
    super().__init__(*args, **kwargs)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^
  File "C:\Users\basti\BastiGame\Development\DevHQ\InternalBot\.venv\Lib\site-packages\discord\ui\view.py", line 249, in __init__
    self.add_item(item)
    ~~~~~~~~~~~~~^^^^^^
  File "C:\Users\basti\BastiGame\Development\DevHQ\InternalBot\.venv\Lib\site-packages\discord\ui\view.py", line 389, in add_item
    raise TypeError(f"expected Item not {item.__class__!r}")
TypeError: expected Item not <class 'dict'>
slender bane
#

there should be a from_dict method on the view itself iirc

#

indeed.

#

though the signature seems to be incorrect

#

Its referencing the actual Component class and not it's TypedDict

distant dome
#

I don't understand how to implement this. Do you have an example?

slender bane
#

discord.View.from_dict(json.dumps(YOUR_JSON_DATA))

distant dome
#

This is the data as I store it in the database.

container_json = json.dumps(container.to_component_dict())

{
  "type": 17,
  "id": null,
  "components": [
    {
      "type": 10,
      "id": null,
      "content": "Testing the system"
    },
    {
      "type": 14,
      "id": null,
      "divider": true,
      "spacing": 1
    },
    {
      "type": 10,
      "id": null,
      "content": "![DevHQ](https://cdn.discordapp.com/emojis/1375581305290358855.webp?size=128 "DevHQ") Information provided by :) "
    }
  ],
  "spoiler": false
}

The example you sent doesn't work there, though.

simple pivot
#

I'll add more from_dict methods later