forked from Pycord-Development/pycord
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example of using semi-implemented private emojis. (Pycord-Development…
- Loading branch information
Showing
1 changed file
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |