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