Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add guild preview endpoint #818

Merged
merged 1 commit into from Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -592,6 +592,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 @@ -151,7 +151,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 @@ -567,6 +567,40 @@ type Guild struct {
Permissions int `json:"permissions"`
}

// 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