pycord icon indicating copy to clipboard operation
pycord copied to clipboard

`discord.Emoji` and `discord.PartialEmoji` didn't work in slash option.

Open Sodynoizz opened this issue 2 years ago • 7 comments

Summary

The slash command didn't work when I add slash option which contains Union[discord.Emoji, discord.PartialEmoji] type

Reproduction Steps

I tested code that has attribute type Union[discord.Emoji, discord.PartialEmoji] and this command didn't synced with guilds.

Minimal Reproducible Code

@discord.commands.slash_command(name="test")
async def emoji(self, ctx: discord.ApplicationContext, emoji : Union[discord.Emoji, discord.PartialEmoji]):
        await ctx.respond(emoji.name)

Expected Results

I want the slash option support for discord.Emoji and discord.PartialEmoji

Actual Results

The command didn't synced with guilds.

Intents

intents = discord.Intents.all()

System Information

  • Python v3.10.2-final
  • py-cord v2.0.1-final
  • aiohttp v3.8.1
  • system info: Windows 10 10.0.22000

Checklist

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

Additional Context

No response

Sodynoizz avatar Aug 20 '22 10:08 Sodynoizz

discord.Emoji is not a valid option type.

EmmmaTech avatar Aug 20 '22 16:08 EmmmaTech

Can you try using only discord.Emoji, this should use the converter

Dorukyum avatar Aug 22 '22 08:08 Dorukyum

Can you try using only discord.Emoji, this should use the converter

Code that I tested

@discord.commands.slash_command(name="test")
async def emoji(self, ctx: discord.ApplicationContext, emoji : discord.Emoji):
        await ctx.respond(emoji.name)

I got this error

discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: TypeError: EmojiConverter.convert() missing 1 required positional argument: 'argument'

Sodynoizz avatar Aug 23 '22 14:08 Sodynoizz

This should be fixed in the latest release

plun1331 avatar Aug 26 '22 11:08 plun1331

This should be fixed in the latest release

Well, I tested that code in py-cord version 2.1.1 with 1️⃣ emoji but it raised this error

discord.ext.commands.errors.EmojiNotFound: Emoji "1️⃣" not found.

Sodynoizz avatar Aug 26 '22 11:08 Sodynoizz

This should be fixed in the latest release

Well, I tested that code in py-cord version 2.1.1 with 1️⃣ emoji but it raised this error

discord.ext.commands.errors.EmojiNotFound: Emoji "1️⃣" not found.

Try with a custom emoji, 1️⃣ is technically only a unicode character and not considered an emoji by the parser.

plun1331 avatar Aug 26 '22 14:08 plun1331

Hi, I have related but not the same problem with Emojis.

I made dropdown menu that user can customize with commands. I didn't found any proper way to pass unicode emoji through command. But why would I need a unicode emoji, you might ask? Because discord.SelectOption doesn't like standard discord emoji format (e.g. :bulb), it works with unicode just fine. It also has no problem with cusotm emojis for some reason.

Error message that i get:

Traceback (most recent call last):
  File "/home/rafaln/.local/lib/python3.10/site-packages/discord/bot.py", line 1114, in invoke_application_command
    await ctx.command.invoke(ctx)
  File "/home/rafaln/.local/lib/python3.10/site-packages/discord/commands/core.py", line 375, in invoke
    await injected(ctx)
  File "/home/rafaln/.local/lib/python3.10/site-packages/discord/commands/core.py", line 132, in wrapped
    raise ApplicationCommandInvokeError(exc) from exc
discord.errors.ApplicationCommandInvokeError: Application Command raised an exception: HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In data.components.0.components.0.options.0.emoji.name: Invalid emoji

I used this example and modified it a little bit:

options = [
            discord.SelectOption(
                label="Red", description="Your favourite colour is red", emoji=":smile:"
            ),
            discord.SelectOption(
                label="Green", description="Your favourite colour is green", emoji="⚗"
            ),
            discord.SelectOption(
                label="Blue", description="Your favourite colour is blue", emoji="<:troll:910540961958989934>"
            ),

Caraffa-git avatar Sep 01 '23 20:09 Caraffa-git