#Remove all fields in an embed to append a new list

1 messages · Page 1 of 1 (latest)

pearl mountain
#

The title may sounds confusing but the idea is like this.

help_list: list(interactions.Embed) = []
i: int = 0

for command in self.client.application_commands:
  if len(self.client.application_commands) > 25:

    embed = interactions.Embed(
      title="List of available commands.",
      color=0x7CB7D3,
      thumbnail=interactions.EmbedAttachment(
        url=self.client.user.avatar.url
      ),
    )

So I was like, using pagination for this. If the embed has 25 fields of command, save that embed to the help_list array, clear the embed then append the next list of commands. How can I do this with v5?

Thanks for the help first. Appreciated.

meager rootBOT
#

Hey! Once your issue is solved, press the button below to close this thread!

untold juniper
#

Just make new embed instance

pearl mountain
#

Damn it

untold juniper
pearl mountain
#

I wonder how can the field are empty, as I have add_field after each i increasement

untold juniper
#

Are you sure your code appends fields?

#

oh lmao blue

#

you are creating new embed for every command

pearl mountain
#

Wait what

#

xD

#

How

pearl mountain
#

Found the problem, and there is a bug, I think.

#
Traceback (most recent call last):
  File "/home/codespace/.local/lib/python3.10/site-packages/interactions/client/client.py", line 1712, in __dispatch_interaction
    response = await callback
  File "/home/codespace/.local/lib/python3.10/site-packages/interactions/client/client.py", line 1607, in _run_slash_command
    return await command(ctx, **ctx.kwargs)
  File "/home/codespace/.local/lib/python3.10/site-packages/interactions/models/internal/command.py", line 132, in __call__
    await self.call_callback(self.callback, context)
  File "/home/codespace/.local/lib/python3.10/site-packages/interactions/models/internal/application_commands.py", line 770, in call_callback
    return await self.call_with_binding(callback, ctx)
  File "/home/codespace/.local/lib/python3.10/site-packages/interactions/models/internal/callback.py", line 43, in call_with_binding
    return await callback(*args, **kwargs)
  File "/workspaces/Articuno/exts/core/help.py", line 60, in help
    await paginator.send(ctx)
  File "/home/codespace/.local/lib/python3.10/site-packages/interactions/ext/paginators.py", line 366, in send
    self._message = await ctx.send(**self.to_dict())
  File "/home/codespace/.local/lib/python3.10/site-packages/interactions/ext/paginators.py", line 352, in to_dict
    "components": [c.to_dict() for c in self.create_components()],
  File "/home/codespace/.local/lib/python3.10/site-packages/interactions/ext/paginators.py", line 291, in create_components
    emoji=PartialEmoji.from_dict(process_emoji(self.first_button_emoji)),
  File "/home/codespace/.local/lib/python3.10/site-packages/interactions/models/discord/emoji.py", line 254, in process_emoji
    emoji = PartialEmoji.from_str(emoji)
  File "/home/codespace/.local/lib/python3.10/site-packages/interactions/models/discord/emoji.py", line 76, in from_str
    if _emoji_list := emoji.distinct_emoji_list(emoji_str):
AttributeError: module 'emoji' has no attribute 'distinct_emoji_list'
#

Current code:

embed = interactions.Embed(
    title="List of available commands.",
    color=0x7CB7D3,
    thumbnail=interactions.EmbedAttachment(
        url=self.client.user.avatar.url
    ),
)
help_list = []
i = 0

for command_index, command in enumerate(self.client.application_commands):
    if isinstance(command, interactions.SlashCommand):
        if i == 15:
            help_list.append(embed)
            i = 0
            embed = interactions.Embed(
                title="List of available commands.",
                color=0x7CB7D3,
                thumbnail=interactions.EmbedAttachment(
                    url=self.client.user.avatar.url
                ),
            )

        if command.sub_cmd_name is None:
            embed.add_field(
                name=f"/{command.name}", value=command.description
            )
        else:
            if str(command.sub_cmd_name) != "None":
                embed.add_field(
                    name=f"/{command.name} {command.sub_cmd_name}",
                    value=f"{command.sub_cmd_description}",
                )

        i += 1

paginator = Paginator.create_from_embeds(self.client, *help_list)
await paginator.send(ctx)
untold juniper
#

there module emoji.py and library emoji

pearl mountain
#

Hmm, what do you mean?

untold juniper
#

i.py depends emoji library but it can't import it because there is emoji.py module and python imports it firstly

pearl mountain
#

Seems like a lib error.

pearl mountain
#

Reviving this…

cloud verge
#

Huh I didn't get that ping

#

Just woke up. Give me a few and I'll have a look

cloud verge
#

i cant replicate

#

do you have a file in your repo that may be shadowing the emoji library?

pearl mountain
#

There was a file named “emoji.py” but it is in another folder.

cloud verge
#

humour me and refactor it to a new name

pearl mountain
#

Somehow, I pushed it on Railway and it worked, but not on my local machine.

#

Got that.

pearl mountain
cloud verge
#

it wouldnt work?

#

as in same error?

pearl mountain
#

Yeah

cloud verge
#

unfortunately, your issue is there is something on your system shadowing the emoji library that the lib uses - as to what, im unsure

pearl mountain
#

Hmm.

pearl mountain
#

Let me try deleting that file completely.

pearl mountain
#

GitHub Codespace is causing this out of nowhere.

#

But on my fully local machine completely, it works.

cloud verge
#

weird

pearl mountain
#

Hmm.

#

I guess I learned a lesson.

#

Never trust someone's cloud machine.

pearl mountain
# cloud verge weird

Polls, I think the result was quite weird, can you take a look?

It works now, but like, this wasn't something that I expected. The first page was just 2 commands, 2nd page was the same but 3rd page is like, everything.

#

They got splitted in such a weird way.

#

Here's my code.

        embed = interactions.Embed(
            title="List of available commands.",
            color=0x7CB7D3,
            thumbnail=interactions.EmbedAttachment(
                url=self.client.user.avatar.url
            ),
        )
        help_list = []
        i = 0

        for command_index, command in enumerate(
            self.client.application_commands
        ):
            if isinstance(command, interactions.SlashCommand):
                if i == 15:
                    help_list.append(embed)
                    i = 0
                    embed = interactions.Embed(
                        title="List of available commands.",
                        color=0x7CB7D3,
                        thumbnail=interactions.EmbedAttachment(
                            url=self.client.user.avatar.url
                        ),
                    )

                if command.sub_cmd_name is None:
                    embed.add_field(
                        name=f"/{command.name}", value=command.description
                    )
                else:
                    if str(command.sub_cmd_name) != "None":
                        embed.add_field(
                            name=f"/{command.name} {command.sub_cmd_name}",
                            value=f"{command.sub_cmd_description}",
                        )

                i += 1
#

Are extensions in different folders also affect this, I wonder?

#

Wait, nevermind, I know why now.

#

Turns out that I didn't check for sub_cmd_name and normal command name.