简体   繁体   中英

How to convert string to discord.Emoji class in discord.py?

Here is the code of mine:

@client.command()
async def emote(ctx, *reaction:list):


    await ctx.channel.purge(limit=1)

    if len(reaction) == 0: 
        emotecommandHelp = discord.Embed(title= 'Help for the Emote command', description=f'{client.command_prefix}emote (text, no need for space)')
        await ctx.send(embed = emotecommandHelp)

    
    messagesID = await ctx.channel.history(limit=2).flatten()  #earlier===> later
    messagesID = messagesID[0]


    message = await ctx.channel.fetch_message(messagesID.id)

    if len(reaction) != 1:
        reaction2 = [''.join(x) for x in reaction]
        reaction = ''.join(reaction2)
        reaction = list([x for x in reaction])  
        emotes = list(map(lambda szoveg : f":regional_indicator_{szoveg}:",reaction)) 
        for i in emotes:
            await message.add_reaction(i)
        
    else: 
        emotes = list(map(lambda szoveg : f":regional_indicator_{szoveg}:",reaction[0]))
        for i in emotes:
            
            await message.add_reaction(i)

at this point the emotes list is full with this deafult emotes like:

":regional_indicator_a:", ":regional_indicator_b:", ":regional_indicator_c:" ... as strings

And I dont know how to add them as reactions, cause the way i tried, it raise an Error.

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: 400 Bad Request (error code: 10014): Unknown Emoji

Do you have any ideas how to solve this? I also dont have the info of the IDs

It's <:emoji_name:emoji_id> for custom emojis.

You can also find the discord.Emoji instance through Server.emojis and then cast it to str.

From: https://github.com/Rapptz/discord.py/issues/390

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM