github.com/diamondburned/arikawa/v2@v2.1.0/api/role.go (about) 1 package api 2 3 import ( 4 "github.com/diamondburned/arikawa/v2/discord" 5 "github.com/diamondburned/arikawa/v2/utils/httputil" 6 "github.com/diamondburned/arikawa/v2/utils/json/option" 7 ) 8 9 // Adds a role to a guild member. 10 // 11 // Requires the MANAGE_ROLES permission. 12 func (c *Client) AddRole(guildID discord.GuildID, userID discord.UserID, roleID discord.RoleID) error { 13 return c.FastRequest( 14 "PUT", 15 EndpointGuilds+guildID.String()+"/members/"+userID.String()+"/roles/"+roleID.String(), 16 ) 17 } 18 19 // RemoveRole removes a role from a guild member. 20 // 21 // Requires the MANAGE_ROLES permission. 22 // Fires a Guild Member Update Gateway event. 23 func (c *Client) RemoveRole(guildID discord.GuildID, userID discord.UserID, roleID discord.RoleID) error { 24 return c.FastRequest( 25 "DELETE", 26 EndpointGuilds+guildID.String()+"/members/"+userID.String()+"/roles/"+roleID.String(), 27 ) 28 } 29 30 // Roles returns a list of role objects for the guild. 31 func (c *Client) Roles(guildID discord.GuildID) ([]discord.Role, error) { 32 var roles []discord.Role 33 return roles, c.RequestJSON(&roles, "GET", EndpointGuilds+guildID.String()+"/roles") 34 } 35 36 // https://discord.com/developers/docs/resources/guild#create-guild-role-json-params 37 type CreateRoleData struct { 38 // Name is the name of the role. 39 // 40 // Default: "new role" 41 Name string `json:"name,omitempty"` 42 // Permissions is the bitwise value of the enabled/disabled permissions. 43 // 44 // Default: @everyone permissions in guild 45 Permissions discord.Permissions `json:"permissions,string,omitempty"` 46 // Color is the RGB color value of the role. 47 // 48 // Default: 0 49 Color discord.Color `json:"color,omitempty"` 50 // Hoist specifies whether the role should be displayed separately in the 51 // sidebar. 52 // 53 // Default: false 54 Hoist bool `json:"hoist,omitempty"` 55 // Mentionable specifies whether the role should be mentionable. 56 // 57 // Default: false 58 Mentionable bool `json:"mentionable,omitempty"` 59 } 60 61 // CreateRole creates a new role for the guild. 62 // 63 // Requires the MANAGE_ROLES permission. 64 // Fires a Guild Role Create Gateway event. 65 func (c *Client) CreateRole(guildID discord.GuildID, data CreateRoleData) (*discord.Role, error) { 66 67 var role *discord.Role 68 return role, c.RequestJSON( 69 &role, "POST", 70 EndpointGuilds+guildID.String()+"/roles", 71 httputil.WithJSONBody(data), 72 ) 73 } 74 75 // https://discord.com/developers/docs/resources/guild#modify-guild-role-positions-json-params 76 type MoveRoleData struct { 77 // ID is the id of the role. 78 ID discord.RoleID `json:"id"` 79 // Position is the sorting position of the role. 80 Position option.NullableInt `json:"position,omitempty"` 81 } 82 83 // MoveRole modifies the positions of a set of role objects for the guild. 84 // 85 // Requires the MANAGE_ROLES permission. 86 // Fires multiple Guild Role Update Gateway events. 87 func (c *Client) MoveRole(guildID discord.GuildID, data []MoveRoleData) ([]discord.Role, error) { 88 var roles []discord.Role 89 return roles, c.RequestJSON( 90 &roles, "PATCH", 91 EndpointGuilds+guildID.String()+"/roles", 92 httputil.WithJSONBody(data), 93 ) 94 } 95 96 // https://discord.com/developers/docs/resources/guild#modify-guild-role-json-params 97 type ModifyRoleData struct { 98 // Name is the name of the role. 99 Name option.NullableString `json:"name,omitempty"` 100 // Permissions is the bitwise value of the enabled/disabled permissions. 101 Permissions *discord.Permissions `json:"permissions,string,omitempty"` 102 // Permissions is the bitwise value of the enabled/disabled permissions. 103 Color option.NullableColor `json:"color,omitempty"` 104 // Hoist specifies whether the role should be displayed separately in the 105 // sidebar. 106 Hoist option.NullableBool `json:"hoist,omitempty"` 107 // Mentionable specifies whether the role should be mentionable. 108 Mentionable option.NullableBool `json:"mentionable,omitempty"` 109 } 110 111 // ModifyRole modifies a guild role. 112 // 113 // Requires the MANAGE_ROLES permission. 114 func (c *Client) ModifyRole( 115 guildID discord.GuildID, roleID discord.RoleID, 116 data ModifyRoleData) (*discord.Role, error) { 117 118 var role *discord.Role 119 return role, c.RequestJSON( 120 &role, "PATCH", 121 EndpointGuilds+guildID.String()+"/roles/"+roleID.String(), 122 httputil.WithJSONBody(data), 123 ) 124 } 125 126 // DeleteRole deletes a guild role. 127 // 128 // Requires the MANAGE_ROLES permission. 129 func (c *Client) DeleteRole(guildID discord.GuildID, roleID discord.RoleID) error { 130 return c.FastRequest( 131 "DELETE", 132 EndpointGuilds+guildID.String()+"/roles/"+roleID.String(), 133 ) 134 }