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

标签 python python-3.x discord.py

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

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

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

或者我可以将字符串转换为 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/

相关文章:

python - 如果第一个数字和长度相同,则从列表中删除数字

python - 类型错误 : __init__() got an unexpected keyword argument 'requote'

python - 我想让我的不和谐机器人每小时加入一次语音聊天

python - 在 Ubuntu 14.04 上安装 tensorflow

python - 在 python 中,如何在后台将参数传递给嵌套函数?

python - 在 python 上使用 TensorRT .engine 文件进行推理

python - Discord.py-rewrite - close() 和 logout() 方法之间的区别?

python - 引号引起的语法错误

python - 为什么 python 以东方字符写入我的 CSV 文件?

python-3.x - Keras ValueError : ValueError: Error when checking target: expected dense_4 to have shape (None, 2) 但得到了形状为 (2592, 1) Python3 的数组