我正在尝试创建一个命令,使机器人以更大的表情符号响应您的消息(!big :emoji:)。有没有办法做到这一点?
更新:有没有办法对所有表情符号而不只是自定义表情符号执行此操作?
您只需获取自定义不和谐表情符号的 url,或使用 twitter 表情符号 api 获取默认表情符号的图像
@bot.command()
async def emoji(ctx, emoji: Union[discord.Emoji, discord.PartialEmoji, str]):
"""Post a large size emojis in chat."""
if not isinstance(emoji, str): # if it is a custom discord emoji
d_emoji = cast(discord.Emoji, emoji)
ext = "gif" if d_emoji.animated else "png"
url = d_emoji.url
filename = f"{d_emoji.name}.{ext}"
else: # use the twitter emoji api
try:
cdn_fmt = "https://twemoji.maxcdn.com/2/72x72/{codepoint:x}.png"
url = cdn_fmt.format(codepoint=ord(str(emoji)))
filename = "emoji.png"
except TypeError:
return await ctx.send("That doesn't appear to be a valid emoji")
try: # read it with BytesIO so you dont need to save the image
async with aiohttp.ClientSession() as session:
async with session.get(url) as resp:
image = os.BytesIO(await resp.read())
except Exception:
return await ctx.send("That doesn't appear to be a valid emoji")
file = discord.File(image, filename=filename)
await ctx.send(file=file)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)