Rapptz / discord.py

An API wrapper for Discord written in Python.
http://discordpy.rtfd.org/en/latest
MIT License
14.51k stars 3.74k forks source link

discord.Guild.create_sticker emoji parameter issue #8464

Open BlueRikoroo opened 1 year ago

BlueRikoroo commented 1 year ago

Summary

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

Reproduction Steps

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

Checklist

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

Rapptz commented 1 year ago

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.

BlueRikoroo commented 1 year ago

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

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

Rapptz commented 1 year ago

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.

Vexs commented 1 year ago

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