gpt4 book ai didi

python - 如何将带有表情符号名称的字符串转换为不和谐的表情符号?

转载 作者:行者123 更新时间:2023-12-02 02:39:40 29 4
gpt4 key购买 nike

假设我有一个带有表情符号名称的字符串,例如 emoji = 'fishing_pole_and_fish'

有没有办法在不出现错误的情况下执行msg.add_reaction(emoji):

discord.ext.commands.errors.CommandInvokeError: Command raised anexception: HTTPException: 400 Bad Request (error code: 10014): UnknownEmoji

或者我可以将字符串转换为 discord.Emoji 吗?

我知道我可以使用'\N{FISHING POLE AND FISH}',但我需要它作为'fishing_pole_and_fish',这样我就可以用它做其他事情。此外,钓鱼竿和鱼只是表情符号的一个示例

最佳答案

您查看过emoji module吗? ?

为了让机器人能够对标准内置表情符号使用react,它需要表情符号是符号“🎣”,而不是“:fishing_pole:”,它仅适用于自定义表情符号 <:name:id> .

import emoji

string = ":fishing_pole:"
demoji = emoji.demojize("🎣 ") # This takes the emoji and gives--> :fishing_pole:
emoji = emoji.emojize(string) # This takes :fishing_pole: and gives--> 🎣
print(demoji)
print(emoji)

它确实需要两边都有“:”,否则它不会工作。但您可以添加 ''.join(":"+string+":")如果需要的话

关于python - 如何将带有表情符号名称的字符串转换为不和谐的表情符号?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63812797/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com