def steal_emoji(self, ctx: DogbotContext, emoji: EmojiStealer, name=None):
"""
Imports an external emoji into this server.
You can specify an emoji ID, the custom emoji itself, or "recent" to make the bot scan for recent messages
with a custom emoji that isn't already in this server. If you provide a name, the bot will use that when
uploading the emoji, instead of the name it finds. The name parameter is mandatory if you specify an emoji ID.
"""
emoji_url = f'https://cdn.discordapp.com/emojis/{emoji[0]}.png'
if not emoji.name and not name:
return await ctx.send('You must provide the name for the stolen emoji.')
# strip colons from name if they are there
name = None if not name else name.strip(':')
msg = await ctx.send('Downloading...')
try:
async with ctx.bot.session.get(emoji_url) as emoji_resp:
emoji_bytes = await emoji_resp.read()
if emoji_resp.status != 200 or not emoji_bytes:
return await ctx.send('Failed to download the emoji.')
# steal
emoji = await ctx.guild.create_custom_emoji(name=name or emoji.name, image=emoji_bytes)
# as confirmation, attempt to add react to the comamnd message with it, and fall back to ok
try:
await msg.edit(content=str(emoji))
await msg.add_reaction(f'{emoji.name}:{emoji.id}')
except discord.HTTPException:
await ctx.ok()
except aiohttp.ClientError:
await msg.edit(content='Failed to download the emoji.')
except discord.HTTPException:
await msg.edit(content='Failed to upload the emoji.')
评论列表
文章目录