File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change
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" )
You can’t perform that action at this time.
0 commit comments