discord.py - 如何使机器人能够显示来自任何服务器的任何表情符号的链接
问题描述
所以这个命令有效,但......
@commands.command()
async def se(self, ctx, emoji: discord.Emoji):
await ctx.send(f"**Name:**Illdo this later **Link:**{emoji.url}")
它仅适用于机器人所在服务器的表情符号。有谁知道如何使它能够获取任何服务器表情符号的链接?即使机器人不在其中,如果您愿意,我也需要帮助来显示表情符号的名称
我要做的事情是
解决方案
您需要获取表情符号的 id 并制作 url 本身
你可以id
通过一些得到它,split()
你还需要检查它是否是动画的,以便我们可以使用.gif
并.png
相应地使用
下面是代码:
@commands.command()
async def se(self, ctx, *, msg):
_id = msg.split(":") # split by ":"
if "<a" == _id[0]: # animated emojis structure <a:name:id>
ext = "gif"
else:
ext = "png" # normal emojis structure <name:id>
e_id = _id[2].split(">")[0].strip()# get the id
# url for a emoji is like this, try yourself if you want to check by manually copying any emoji's url
url = f"https://cdn.discordapp.com/emojis/{e_id}.{ext}"
await ctx.send(f"**Name**: :{_id[1]}: **Link**: {url}")
推荐阅读
- java - PDFBox - 可访问的 PDF - 如何根据可访问性指南检查 PDF 标签是否具有属性
- python - 使用 Python 内联修改 Hl7 消息。
- karate - 空手道 API:在附加的 json 响应中如何动态更新 json 属性数量
- spring-boot - Docker 必须构建 spring 应用程序然后运行它
- objective-c - 将 SDK 中的自定义 Docset 集成到 Xcode 10 的文档窗口中
- excel - 如何修复“VBA 只运行一部分代码而忽略另一部分”
- msbuild - 导入元素未正确展开 ItemGroup
- python-3.x - 如何使用 np.savetxt 保存不同的 numpy 数组?
- javascript - 如何使 iframe 与网络摄像头一起使用?[p5 & tensorflow.js]
- java - 读取文件,文件“不存在”