Skip to content

Commit

Permalink
Add guild preview endpoint (#818)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jleagle committed Feb 24, 2021
1 parent 2021f60 commit 4617d8e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
1 change: 1 addition & 0 deletions endpoints.go
Expand Up @@ -78,6 +78,7 @@ var (
EndpointUserNotes = func(uID string) string { return EndpointUsers + "@me/notes/" + uID }

EndpointGuild = func(gID string) string { return EndpointGuilds + gID }
EndpointGuildPreview = func(gID string) string { return EndpointGuilds + gID + "/preview" }
EndpointGuildChannels = func(gID string) string { return EndpointGuilds + gID + "/channels" }
EndpointGuildMembers = func(gID string) string { return EndpointGuilds + gID + "/members" }
EndpointGuildMember = func(gID, uID string) string { return EndpointGuilds + gID + "/members/" + uID }
Expand Down
12 changes: 12 additions & 0 deletions restapi.go
Expand Up @@ -588,6 +588,18 @@ func (s *Session) Guild(guildID string) (st *Guild, err error) {
return
}

// GuildPreview returns a GuildPreview structure of a specific public Guild.
// guildID : The ID of a Guild
func (s *Session) GuildPreview(guildID string) (st *GuildPreview, err error) {
body, err := s.RequestWithBucketID("GET", EndpointGuildPreview(guildID), nil, EndpointGuildPreview(guildID))
if err != nil {
return
}

err = unmarshal(body, &st)
return
}

// GuildCreate creates a new Guild
// name : A name for the Guild (2-100 characters)
func (s *Session) GuildCreate(name string) (st *Guild, err error) {
Expand Down
36 changes: 35 additions & 1 deletion structs.go
Expand Up @@ -152,7 +152,7 @@ type Integration struct {
SyncedAt Timestamp `json:"synced_at"`
}

//ExpireBehavior of Integration
// ExpireBehavior of Integration
// https://discord.com/developers/docs/resources/guild#integration-object-integration-expire-behaviors
type ExpireBehavior int

Expand Down Expand Up @@ -572,6 +572,40 @@ type Guild struct {
Permissions int64 `json:"permissions,string"`
}

// A GuildPreview holds data related to a specific public Discord Guild, even if the user is not in the guild.
type GuildPreview struct {
// The ID of the guild.
ID string `json:"id"`

// The name of the guild. (2–100 characters)
Name string `json:"name"`

// The hash of the guild's icon. Use Session.GuildIcon
// to retrieve the icon itself.
Icon string `json:"icon"`

// The hash of the guild's splash.
Splash string `json:"splash"`

// The hash of the guild's discovery splash.
DiscoverySplash string `json:"discovery_splash"`

// A list of the custom emojis present in the guild.
Emojis []*Emoji `json:"emojis"`

// The list of enabled guild features
Features []string `json:"features"`

// Approximate number of members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
ApproximateMemberCount int `json:"approximate_member_count"`

// Approximate number of non-offline members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
ApproximatePresenceCount int `json:"approximate_presence_count"`

// the description for the guild
Description string `json:"description"`
}

// MessageNotifications is the notification level for a guild
// https://discord.com/developers/docs/resources/guild#guild-object-default-message-notification-level
type MessageNotifications int
Expand Down

0 comments on commit 4617d8e

Please sign in to comment.