Discord.py 机器人不发送键帽表情符号

Discord.py bot doesn't send keycap emojis

我尝试创建一个简单的菜单系统,并将反应用作机器人中的按钮。问题是,每次我尝试发送表情符号(数字表情符号,菜单中的每个命令一个)时,Discord 都会报错:未知表情符号。这是我使用的方法:

async def show_buttons(embed_object, menu, message):
    emojis = ['1️⃣','2️⃣','3️⃣','4️⃣','5️⃣','6️⃣','7️⃣','8️⃣','9️⃣']
    human_user = message.author
    msg = await client.send_message(message.channel, embed=embed_object)
    for command, emoji in zip(game_engine.buttons[menu], emojis): 
        await client.add_reaction(msg, emoji)
    res = await client.wait_for_reaction(emojis, user=human_user, message=msg)
    await client.send_message(message.channel, '{0.user} reacted with {0.reaction.emoji}!'.format(res))
    ...REST OF CODE GOES HERE...

game_engine.buttons[menu] 是标记为 1-9 的命令列表,embed_object 是以特定方式格式化的菜单。

总是returns错误:discord.errors.HTTPException: BAD REQUEST (status code: 400): Unknown Emoji

我该怎么办?

像这样使用 unicode 时,我更喜欢使用名称转义,因为许多 unicode 字符看起来非常相似。当我使用该列表的第一个表情符号并在

中使用它时
def get_name(s):
    return s.encode('ascii', 'namereplace')

我得到 b'1\N{VARIATION SELECTOR-16}\N{COMBINING ENCLOSING KEYCAP}'。但是当我发出命令时

@bot.command()
async def emojiname(emoji):
    await bot.say(get_name(emoji))

和运行 !emojiname :one:,我得到b'1\N{COMBINING ENCLOSING KEYCAP}'

所以你只需要改变你定义表情符号的方式。我建议这样做:

emojis = ["{}\N{COMBINING ENCLOSING KEYCAP}".format(num) for num in range(1, 10)]