github.com/diamondburned/arikawa@v1.3.14/api/invite.go (about) 1 package api 2 3 import ( 4 "github.com/diamondburned/arikawa/discord" 5 "github.com/diamondburned/arikawa/utils/httputil" 6 "github.com/diamondburned/arikawa/utils/json/option" 7 ) 8 9 var EndpointInvites = Endpoint + "invites/" 10 11 // Invite returns an invite object for the given code. 12 // 13 // ApproxMembers will not get filled. 14 func (c *Client) Invite(code string) (*discord.Invite, error) { 15 var inv *discord.Invite 16 return inv, c.RequestJSON( 17 &inv, "GET", 18 EndpointInvites+code, 19 ) 20 } 21 22 // Invite returns an invite object for the given code and fills ApproxMembers. 23 func (c *Client) InviteWithCounts(code string) (*discord.Invite, error) { 24 var params struct { 25 WithCounts bool `schema:"with_counts,omitempty"` 26 } 27 28 params.WithCounts = true 29 30 var inv *discord.Invite 31 return inv, c.RequestJSON( 32 &inv, "GET", 33 EndpointInvites+code, 34 httputil.WithSchema(c, params), 35 ) 36 } 37 38 // ChannelInvites returns a list of invite objects (with invite metadata) for 39 // the channel. Only usable for guild channels. 40 // 41 // Requires the MANAGE_CHANNELS permission. 42 func (c *Client) ChannelInvites(channelID discord.ChannelID) ([]discord.Invite, error) { 43 var invs []discord.Invite 44 return invs, c.RequestJSON(&invs, "GET", 45 EndpointChannels+channelID.String()+"/invites") 46 } 47 48 // GuildInvites returns a list of invite objects (with invite metadata) for the 49 // guild. 50 // 51 // Requires the MANAGE_GUILD permission. 52 func (c *Client) GuildInvites(guildID discord.GuildID) ([]discord.Invite, error) { 53 var invs []discord.Invite 54 return invs, c.RequestJSON(&invs, "GET", 55 EndpointGuilds+guildID.String()+"/invites") 56 } 57 58 // https://discord.com/developers/docs/resources/channel#create-channel-invite-json-params 59 type CreateInviteData struct { 60 // MaxAge is the duration of invite in seconds before expiry, or 0 for 61 // never. 62 // 63 // Default: 86400 (24 hours) 64 MaxAge option.Uint `json:"max_age,omitempty"` 65 // MaxUses is the max number of uses or 0 for unlimited. 66 // 67 // Default: 0 68 MaxUses uint `json:"max_uses,omitempty"` 69 // Temporary specifies whether this invite only grants temporary membership. 70 // 71 // Default: false 72 Temporary bool `json:"temporary,omitempty"` 73 // Unique has the following behavior: if true, don't try to reuse a similar 74 // invite (useful for creating many unique one time use invites). 75 // 76 // Default: false 77 Unique bool `json:"unique,omitempty"` 78 } 79 80 // CreateInvite creates a new invite object for the channel. Only usable for 81 // guild channels. 82 // 83 // Requires the CREATE_INSTANT_INVITE permission. 84 func (c *Client) CreateInvite( 85 channelID discord.ChannelID, data CreateInviteData) (*discord.Invite, error) { 86 var inv *discord.Invite 87 return inv, c.RequestJSON( 88 &inv, "POST", 89 EndpointChannels+channelID.String()+"/invites", 90 httputil.WithJSONBody(data), 91 ) 92 } 93 94 // DeleteInvite deletes an invite. 95 // 96 // Requires the MANAGE_CHANNELS permission on the channel this invite belongs 97 // to, or MANAGE_GUILD to remove any invite across the guild. 98 // Fires a Invite Delete Gateway event. 99 func (c *Client) DeleteInvite(code string) (*discord.Invite, error) { 100 var inv *discord.Invite 101 return inv, c.RequestJSON(&inv, "DELETE", EndpointInvites+code) 102 }