github.com/diamondburned/arikawa@v1.3.14/api/emoji.go (about) 1 package api 2 3 import ( 4 "github.com/diamondburned/arikawa/discord" 5 "github.com/diamondburned/arikawa/utils/httputil" 6 ) 7 8 // Emoji is the API format of a regular Emoji, both Unicode or custom. This 9 // could usually be formatted by calling (discord.Emoji).APIString(). 10 type Emoji = string 11 12 // NewCustomEmoji creates a new Emoji using a custom guild emoji as 13 // base. 14 // Unicode emojis should be directly passed to the function using Emoji. 15 func NewCustomEmoji(id discord.EmojiID, name string) Emoji { 16 return name + ":" + id.String() 17 } 18 19 // Emojis returns a list of emoji objects for the given guild. 20 func (c *Client) Emojis(guildID discord.GuildID) ([]discord.Emoji, error) { 21 var e []discord.Emoji 22 return e, c.RequestJSON(&e, "GET", EndpointGuilds+guildID.String()+"/emojis") 23 } 24 25 // Emoji returns an emoji object for the given guild and emoji IDs. 26 func (c *Client) Emoji(guildID discord.GuildID, emojiID discord.EmojiID) (*discord.Emoji, error) { 27 var emj *discord.Emoji 28 return emj, c.RequestJSON(&emj, "GET", 29 EndpointGuilds+guildID.String()+"/emojis/"+emojiID.String()) 30 } 31 32 // https://discord.com/developers/docs/resources/emoji#create-guild-emoji-json-params 33 type CreateEmojiData struct { 34 // Name is the name of the emoji. 35 Name string `json:"name"` 36 // Image is the the 128x128 emoji image. 37 Image Image `json:"image"` 38 // Roles are the roles for which this emoji will be whitelisted. 39 Roles *[]discord.RoleID `json:"roles,omitempty"` 40 } 41 42 // CreateEmoji creates a new emoji in the guild. This endpoint requires 43 // MANAGE_EMOJIS. ContentType must be "image/jpeg", "image/png", or 44 // "image/gif". However, ContentType can also be automatically detected 45 // (though shouldn't be relied on). 46 // Emojis and animated emojis have a maximum file size of 256kb. 47 func (c *Client) CreateEmoji(guildID discord.GuildID, data CreateEmojiData) (*discord.Emoji, error) { 48 49 // Max 256KB 50 if err := data.Image.Validate(256 * 1000); err != nil { 51 return nil, err 52 } 53 54 var emj *discord.Emoji 55 return emj, c.RequestJSON( 56 &emj, "POST", 57 EndpointGuilds+guildID.String()+"/emojis", 58 httputil.WithJSONBody(data), 59 ) 60 } 61 62 // https://discord.com/developers/docs/resources/emoji#modify-guild-emoji-json-params 63 type ModifyEmojiData struct { 64 // Name is the name of the emoji. 65 Name string `json:"name,omitempty"` 66 // Roles are the roles to which this emoji will be whitelisted. 67 Roles *[]discord.RoleID `json:"roles,omitempty"` 68 } 69 70 // ModifyEmoji changes an existing emoji. This requires MANAGE_EMOJIS. Name and 71 // roles are optional fields (though you'd want to change either though). 72 // 73 // Fires a Guild Emojis Update Gateway event. 74 func (c *Client) ModifyEmoji(guildID discord.GuildID, emojiID discord.EmojiID, data ModifyEmojiData) error { 75 return c.FastRequest( 76 "PATCH", 77 EndpointGuilds+guildID.String()+"/emojis/"+emojiID.String(), 78 httputil.WithJSONBody(data), 79 ) 80 } 81 82 // Delete the given emoji. 83 // 84 // Requires the MANAGE_EMOJIS permission. 85 // Fires a Guild Emojis Update Gateway event. 86 func (c *Client) DeleteEmoji(guildID discord.GuildID, emojiID discord.EmojiID) error { 87 return c.FastRequest("DELETE", EndpointGuilds+guildID.String()+"/emojis/"+emojiID.String()) 88 }