Skip to content

Commit 728f1d1

Browse files
authored
Example of using semi-implemented private emojis. (#1465)
1 parent 28d003f commit 728f1d1

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

examples/create_private_emoji.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import discord
2+
3+
bot = discord.Bot()
4+
5+
allowed_content_types = ['image/jpeg', 'image/png'] # Setting up allowed attachments types
6+
7+
8+
# Discord doesn't support creating private emojis by default, its semi-implemented feature and can be done by bots only.
9+
10+
# This command is publicly available, to set up command permissions look for other examples in repo
11+
@bot.command(guild_ids=[...])
12+
async def add_private_emoji(
13+
ctx, name: discord.Option(str),
14+
image: discord.Option(discord.Attachment),
15+
role: discord.Option(discord.Role)
16+
):
17+
if image.content_type not in allowed_content_types:
18+
return await ctx.respond("Invalid attachment type!", ephemeral=True)
19+
20+
image_file = await image.read() # Reading attachment's content to get bytes
21+
22+
await ctx.guild.create_custom_emoji(name=name, image=image_file, roles=[role]) # Image argument only takes bytes!
23+
await ctx.respond(content="Private emoji is successfully created!")
24+
25+
26+
bot.run("TOKEN")

0 commit comments

Comments
 (0)