簡體   English   中英

如何在 discord.py 中將字符串轉換為 discord.Emoji class?

[英]How to convert string to discord.Emoji class in discord.py?

這是我的代碼:

@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)

在這一點上,表情列表中充滿了這種默認的表情,例如:

":regional_indicator_a:", ":regional_indicator_b:", ":regional_indicator_c:" ... 作為字符串

而且我不知道如何將它們添加為反應,因為我嘗試的方式會引發錯誤。

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

你有什么想法如何解決這個問題嗎? 我也沒有身份證信息

<:emoji_name:emoji_id>用於自定義表情符號。

您也可以通過Server.emojis找到discord.Emoji實例,然后將其轉換為str。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM