discord.py icon indicating copy to clipboard operation
discord.py copied to clipboard

discord.Guild.create_sticker emoji parameter issue

Open BlueRikoroo opened this issue 2 years ago • 4 comments

Summary

Emojis added to stickers upon creation don't seem to work

Reproduction Steps

  • Have a bot client commands.Bot()
  • Create a sticker with a valid Name, Description, File, and Reason. This works by itself guild.create_sticker
  • Try to also add an emoji in the parameter of either discord.Guild.create_sticker or discord.GuildSticker.edit. The emoji will not be present when checking after or restarting Discord. guildSticker.edit(emoji="👌")

Minimal Reproducible Code

# guild is a valid discord.Guild object
await guild.create_sticker(name="Test", description="Test Desc",
                           emoji="👌", file=discord.File("PathIrrelevant"), reason="Test")

Expected Results

Emoji should be added / edited onto the sticker in the "Related Emoji" slot when checking the sticker in the stickers section of the guild.

Actual Results

The "Related Emoji" slot is left blank (or otherwise unchanged)

Intents

discord.Intentes.all()

System Information

  • Python v3.9.6-final
  • discord.py v2.1.0-alpha
    • discord.py metadata: v2.1.0a4563+g0981f122
  • aiohttp v3.7.4.post0
  • system info: Linux 5.10.0-18-amd64 #1 SMP Debian 5.10.140-1 (2022-09-02)

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

In both discord.Guild.create_sticker and discord.GuildSticker.edit, these lines exist: discord.Guild.create_sticker discord.GuildSticker.edit

        try:
            emoji = unicodedata.name(emoji)
        except TypeError:
            pass
        else:
            emoji = emoji.replace(' ', '_')

Using my input, "👌", you get "OK_HAND_SIGN". Thus, the code itself does not have an error.

It then adds that emoji to the 'tags' discord.Guild.create_sticker discord.GuildSticker.edit

        payload['tags'] = emoji

        data = await self._state.http.create_guild_sticker(self.id, payload, file, reason)
        return self._state.store_sticker(self, data)

This seems fine as well. Checking https://discord.com/developers/docs/resources/sticker#create-guild-sticker also supports this to my knowledge.

I did find out using emoji="ok_hand" does work! Thus it seems to be an issue with changing it from emoji to name. I believe there is an inconsistency between what unicodedata.name(emoji) outputs and what discord expects

The following code when replacing the try and except above fixed it for me: emoji

        import emoji as Emoji
        emoji = Emoji.demojize("👌")[1:-1].lower()

Emoji.demojize("👌") outputs ":OK_hand:", removing the first and last character + lowering matches discords style. Not sure how true this is for other emojis. Unfortunatly doing Emoji.emojize(":" + GuildSticker.emoji + ":") does not return "👌" due to :ok_hand: being different from :OK_hand: If you want the unicode from GuildSticker.emoji, I created some code for that

import emoji as EmojiSwap

discordEmojiToUnicodeDict = {n.lower(): v for n, v in EmojiSwap.unicode_codes.get_emoji_unicode_dict("en").items()}
def discordEmojiToUnicode(emoji):
    k = ":" + emoji + ":"
    if k in discordEmojiToUnicodeDict:
        return discordEmojiToUnicodeDict[k]
    else:
        return emoji

Again, I can not confirm if thise works for 100% of discord Emojis Hopefully that helps someone :D

BlueRikoroo avatar Sep 13 '22 21:09 BlueRikoroo

It seems Discord requires you to use their own proprietary emoji name list for the tags. This emoji name list is not exposed anywhere so it cannot be used by the library. Your example works with the emoji library because the names just so happened to be shared.

I think this is something that Discord should either fix or document better because as it stands right now there's no good way to fix this on my end.

Rapptz avatar Sep 13 '22 23:09 Rapptz

It seems Discord requires you to use their own proprietary emoji name list for the tags. This emoji name list is not exposed anywhere so it cannot be used by the library. Your example works with the emoji library because the names just so happened to be shared.

I think this is something that Discord should either fix or document better because as it stands right now there's no good way to fix this on my end.

I completely agree. It appears the only way to truely fix this currently would be to manually go through each of the emoji on the discord client and get their name

  • Go to a place where you can send a message
  • Click Emoji
  • Hover Mouse over a default emoji and record it's :name:
  • Post the emoji with a \ before it or otherwise get it's unicode equivelent and record it
  • Create a dictionary in python to transfer from one to the other.

While not impossible, it is extremely tedious and I don't expect anyone to do that any time soon.

BlueRikoroo avatar Sep 14 '22 00:09 BlueRikoroo

It's been done before and there are various lists doing this, however it's not something I want to include the library due to bloat and difficulty in keeping it up to date.

Rapptz avatar Sep 14 '22 00:09 Rapptz

As a minor plug for one of said lists- https://gist.github.com/Vexs/629488c4bb4126ad2a9909309ed6bd71

Vexs avatar Sep 14 '22 01:09 Vexs