简体   繁体   English

如何在 discord.py 中将字符串转换为 discord.Emoji class?

[英]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 ":regional_indicator_a:", ":regional_indicator_b:", ":regional_indicator_c:" ... 作为字符串

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. <:emoji_name:emoji_id>用于自定义表情符号。

You can also find the discord.Emoji instance through Server.emojis and then cast it to str.您也可以通过Server.emojis找到discord.Emoji实例,然后将其转换为str。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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