作者:我叫yyson_836 | 来源:互联网 | 2022-11-08 16:08
I tried creating a simple menu system and used reactions as buttons in a bot. Problem is, every time I tried to send an emoji (numeric digit emojis, one for each command in the menu), Discord spits out an error: unknown emoji. Here's the method I am using:
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]
is a list of commands that are labeled 1-9 and embed_object
is the menu that is formatted in a specific way.
It always returns the error: discord.errors.HTTPException: BAD REQUEST (status code: 400): Unknown Emoji
What do I do?
1> Patrick Haug..:
我喜欢在使用此类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)]