Pycord-Development / pycord

Pycord is a modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python
https://docs.pycord.dev
MIT License
2.7k stars 459 forks source link

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

Open Sodynoizz opened 2 years ago

Sodynoizz commented 2 years ago

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

Checklist

Additional Context

No response

EmmmaTech commented 2 years ago

discord.Emoji is not a valid option type.

Dorukyum commented 2 years ago

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

Sodynoizz commented 2 years ago

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'
plun1331 commented 2 years ago

This should be fixed in the latest release

Sodynoizz commented 2 years ago

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.
plun1331 commented 2 years ago

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.

Caraffa-git commented 12 months ago

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>"
            ),