InterStella0 / starlight-dpy

A utility library that she uses for discord.py
https://starlight-dpy.readthedocs.io/en/latest/
MIT License
18 stars 4 forks source link

TypeError: expected string or bytes-like object #4

Closed skylarr1227 closed 1 year ago

skylarr1227 commented 1 year ago

So.. I can only assume its something with how our cogs are laid out, but unsure.. Heres the error im getting... Seems to reference prefix but yeah, this is where i got stuck.

TypeError: expected string or bytes-like object
 [Pika] Ignoring exception in view <HelpMenuBot timeout=180.0 children=3> for item <MenuDropDown placeholder='Select a category' min_values=1 max_values=1 disabled=False options=[<SelectOption label='Boost' value='Boost' description='No Documentation' emoji=None default=False>, <SelectOption label='BotList' value='BotList' description='No Documentation' emoji=None default=False>, <SelectOption label='Breeding' value='Breeding' description='No Documentation' emoji=None default=False>, <SelectOption label='Chests' value='Chests' description='Open and view info on Radiant Chests.' emoji=None default=False>, <SelectOption label='Duel' value='Duel' description='Fight pokemon in a duel.' emoji=None default=False>, <SelectOption label='Events' value='Events' description='Various seasonal events in DittoBOT.' emoji=None default=False>]>

 Traceback (most recent call last):
   File "/home/ubuntu/.local/lib/python3.9/site-packages/discord/ui/view.py", line 425, in _scheduled_task
     await item.callback(interaction)
   File "/home/ubuntu/.local/lib/python3.9/site-packages/starlight/help_command/view.py", line 65, in callback
     await self.view.toggle_interface(interaction)
   File "/home/ubuntu/.local/lib/python3.9/site-packages/starlight/help_command/view.py", line 282, in toggle_interface
     await self.display_cog_help(selected_cog, self.__mapping[selected_cog])
   File "/home/ubuntu/.local/lib/python3.9/site-packages/starlight/help_command/view.py", line 287, in display_cog_help
     await pagination.start(self.help_command.context, message=self.help_command.original_message)
   File "/home/ubuntu/.local/lib/python3.9/site-packages/starlight/views/pagination.py", line 260, in start
     kwargs = await self.show_page(resolve_interaction, self.current_page)
   File "/home/ubuntu/.local/lib/python3.9/site-packages/starlight/views/pagination.py", line 239, in show_page
     return await self.get_message_kwargs(interaction, self._data_source[page])
   File "/home/ubuntu/.local/lib/python3.9/site-packages/starlight/views/pagination.py", line 322, in get_message_kwargs
     kwargs = await self.resolved_message_kwargs(interaction, data)
   File "/home/ubuntu/.local/lib/python3.9/site-packages/starlight/views/pagination.py", line 314, in resolved_message_kwargs
     page = await self.__get_kwargs_from_page(interaction, data)
   File "/home/ubuntu/.local/lib/python3.9/site-packages/starlight/views/pagination.py", line 273, in __get_kwargs_from_page
     formed_page = await discord.utils.maybe_coroutine(self.format_page, interaction, data)
   File "/home/ubuntu/.local/lib/python3.9/site-packages/discord/utils.py", line 662, in maybe_coroutine
     return await value
   File "/home/ubuntu/.local/lib/python3.9/site-packages/starlight/help_command/view.py", line 163, in format_page
     return await discord.utils.maybe_coroutine(self.help_command.format_cog_page, self, data)
   File "/home/ubuntu/.local/lib/python3.9/site-packages/discord/utils.py", line 662, in maybe_coroutine
     return await value
   File "/home/ubuntu/.local/lib/python3.9/site-packages/starlight/help_command/command.py", line 462, in format_cog_page
     list_cmds = "\n".join([self.format_command_brief(cmd) for cmd in cmds])
   File "/home/ubuntu/.local/lib/python3.9/site-packages/starlight/help_command/command.py", line 462, in <listcomp>
     list_cmds = "\n".join([self.format_command_brief(cmd) for cmd in cmds])
   File "/home/ubuntu/.local/lib/python3.9/site-packages/starlight/help_command/command.py", line 132, in format_command_brief
     return f"`{self.get_command_signature(command)}`\n{command.short_doc or self.no_documentation}"
   File "/home/ubuntu/.local/lib/python3.9/site-packages/starlight/help_command/command.py", line 118, in get_command_signature
     return f'{self.context.clean_prefix}{command.qualified_name} {command.signature}'
   File "/home/ubuntu/.local/lib/python3.9/site-packages/discord/ext/commands/context.py", line 423, in clean_prefix
     return pattern.sub("@%s" % user.display_name.replace('\\', r'\\'), self.prefix)
 TypeError: expected string or bytes-like object

Our prefix for non-slash commands is on mention of the bot via reply or ping.

InterStella0 commented 1 year ago

What is your commands.Bot instantiation or if you have a bot.get_prefix override, I would need to see that.

skylarr1227 commented 1 year ago

Main dna file, init of bot

class Ditto(commands.AutoShardedBot):
    def __init__(self, cluster_info, *args, **kwargs):
        asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
        # =yield loop
        # loop.close()
        AgnosticClient.get_io_loop = asyncio.get_running_loop
        intents = discord.Intents.none()
        intents.guilds = True
        intents.members = True
        intents.guild_messages = True
        # To be removed once the bot is ready, or september, whichever comes first :P
        intents.message_content = False
        super().__init__(
            command_prefix=get_prefix,
            max_messages=None,
            intents=intents,
            heartbeat_timeout=120,
            owner_ids=OWNER_ID_LIST,
            guild_ready_timeout=10,
            shard_ids=cluster_info["shards"],
            shard_count=cluster_info["total_shards"],
            allowed_mentions=discord.AllowedMentions(everyone=False, roles=False, users=True),
            enable_debug_events=True,
            chunk_guilds_at_startup=False,
            *args,
            **kwargs,
        )
...# continued past this for a while.

definition of get_prefix

async def get_prefix(bot, message):
    prefixes = ['<@1000125868938633297>']
    if not message.guild:
        return "?"
    return commands.when_mentioned_or(*prefixes)(bot, message)

and commands.Bot for that cog? Im not sure which cog it was causing the issue.... and there is a total of 24

InterStella0 commented 1 year ago

This is the result of starlight.convert_help_hybrid replacing ctx.prefix with your bot.get_prefix. I've reverted that line so it doesn't replace it. The goal of that line was to properly display the command prefix signature when the help command is invoked with a slash command, but it is removed now since it is not deemed reasonable to patch things like this.

You can update the library by

pip install -U git+https://github.com/InterStella0/starlight-dpy