Skip to content
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

Setting the emoji property of a SelectOption after initialization raises an exception when sending it #1499

Closed
3 tasks done
justalemon opened this issue Jul 13, 2022 · 0 comments · Fixed by #1550
Closed
3 tasks done
Labels
bug Something isn't working feature request New feature request

Comments

@justalemon
Copy link

justalemon commented Jul 13, 2022

Summary

Setting the emoji property of a SelectOption after initialization raises an exception when sending it

Reproduction Steps

  • Set the emoji property of a SelectOption to "🔴" after initializing the SelectOption

Minimal Reproducible Code

from discord import slash_command, ApplicationContext, SelectOption
from discord.ext.commands import Cog
from discord.ui import View, Select


class CustomSelectOption(SelectOption):
    def __init__(self):
        super().__init__(label="Testing")
        self.emoji = "🔴"


class CustomSelect(Select):
    def __init__(self):
        super().__init__(options=[CustomSelectOption()])


class CustomView(View):
    def __init__(self):
        super().__init__()
        self.add_item(CustomSelect())


class TestCog(Cog):
    def __init__(self, bot):
        self.bot = bot

    @slash_command()
    async def test(self, ctx: ApplicationContext):
        view = CustomView()
        await ctx.respond(view=view)

Expected Results

No exception.

Actual Results

An exception similar to this

Ignoring exception in command test:
Traceback (most recent call last):
  File "D:\Proyectos\Discord\BotTesting\venv\lib\site-packages\discord\commands\core.py", line 127, in wrapped
    ret = await coro(arg)
  File "D:\Proyectos\Discord\BotTesting\venv\lib\site-packages\discord\commands\core.py", line 877, in _invoke
    await self.callback(self.cog, ctx, **kwargs)
  File "D:\Proyectos\Discord\BotTesting\bot\cog.py", line 30, in test
    await ctx.respond(view=view)
  File "D:\Proyectos\Discord\BotTesting\venv\lib\site-packages\discord\commands\context.py", line 258, in respond
    return await self.interaction.response.send_message(*args, **kwargs)  # self.response
  File "D:\Proyectos\Discord\BotTesting\venv\lib\site-packages\discord\interactions.py", line 680, in send_message
    payload["components"] = view.to_components()
  File "D:\Proyectos\Discord\BotTesting\venv\lib\site-packages\discord\ui\view.py", line 216, in to_components
    children = [item.to_component_dict() for item in group]
  File "D:\Proyectos\Discord\BotTesting\venv\lib\site-packages\discord\ui\view.py", line 216, in <listcomp>
    children = [item.to_component_dict() for item in group]
  File "D:\Proyectos\Discord\BotTesting\venv\lib\site-packages\discord\ui\select.py", line 280, in to_component_dict
    return self._underlying.to_dict()
  File "D:\Proyectos\Discord\BotTesting\venv\lib\site-packages\discord\components.py", line 348, in to_dict
    "options": [op.to_dict() for op in self.options],
  File "D:\Proyectos\Discord\BotTesting\venv\lib\site-packages\discord\components.py", line 348, in <listcomp>
    "options": [op.to_dict() for op in self.options],
  File "D:\Proyectos\Discord\BotTesting\venv\lib\site-packages\discord\components.py", line 456, in to_dict
    payload["emoji"] = self.emoji.to_dict()  # type: ignore
AttributeError: 'str' object has no attribute 'to_dict'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "D:\Proyectos\Discord\BotTesting\venv\lib\site-packages\discord\bot.py", line 992, in invoke_application_command
    await ctx.command.invoke(ctx)
  File "D:\Proyectos\Discord\BotTesting\venv\lib\site-packages\discord\commands\core.py", line 358, in invoke
    await injected(ctx)
  File "D:\Proyectos\Discord\BotTesting\venv\lib\site-packages\discord\commands\core.py", line 135, in wrapped
    raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: AttributeError: 'str' object has no attribute 'to_dict

Intents

Default Intents

System Information

  • Python v3.9.10-final
  • py-cord v2.0.0-final
  • aiohttp v3.8.1
  • system info: Windows 10 10.0.19044

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

On initialization, the following code is executed:

        if emoji is not None:
            if isinstance(emoji, str):
                emoji = PartialEmoji.from_str(emoji)
            elif isinstance(emoji, _EmojiTag):
                emoji = emoji._to_partial()
            else:
                raise TypeError(f"expected emoji to be str, Emoji, or PartialEmoji not {emoji.__class__}")

Which is not executed when doing the_select_option.emoji = "🔴".

@justalemon justalemon added the unconfirmed bug A bug report that needs triaging label Jul 13, 2022
@Middledot Middledot added bug Something isn't working feature request New feature request and removed unconfirmed bug A bug report that needs triaging labels Aug 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feature request New feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants