Skip to content

Commit

Permalink
Example of using semi-implemented private emojis. (Pycord-Development…
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGiga authored Jul 3, 2022
1 parent 28d003f commit 728f1d1
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions examples/create_private_emoji.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import discord

bot = discord.Bot()

allowed_content_types = ['image/jpeg', 'image/png'] # Setting up allowed attachments types


# Discord doesn't support creating private emojis by default, its semi-implemented feature and can be done by bots only.

# This command is publicly available, to set up command permissions look for other examples in repo
@bot.command(guild_ids=[...])
async def add_private_emoji(
ctx, name: discord.Option(str),
image: discord.Option(discord.Attachment),
role: discord.Option(discord.Role)
):
if image.content_type not in allowed_content_types:
return await ctx.respond("Invalid attachment type!", ephemeral=True)

image_file = await image.read() # Reading attachment's content to get bytes

await ctx.guild.create_custom_emoji(name=name, image=image_file, roles=[role]) # Image argument only takes bytes!
await ctx.respond(content="Private emoji is successfully created!")


bot.run("TOKEN")

0 comments on commit 728f1d1

Please sign in to comment.