api

package
v1.3.14 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2020 License: ISC Imports: 16 Imported by: 13

Documentation

Overview

Package api provides an interface to interact with the Discord REST API. It handles rate limiting, as well as authorizing and more.

Index

Constants

View Source
const AttachmentSpoilerPrefix = "SPOILER_"

Variables

View Source
var (
	BaseEndpoint = "https://discord.com"
	Version      = "6"
	Path         = "/api/v" + Version

	Endpoint           = BaseEndpoint + Path + "/"
	EndpointGateway    = Endpoint + "gateway"
	EndpointGatewayBot = EndpointGateway + "/bot"
)
View Source
var (
	EndpointAuth  = Endpoint + "auth/"
	EndpointLogin = EndpointAuth + "login"
	EndpointTOTP  = EndpointAuth + "mfa/totp"
)
View Source
var (
	EndpointUsers = Endpoint + "users/"
	EndpointMe    = EndpointUsers + "@me"
)
View Source
var EndpointChannels = Endpoint + "channels/"
View Source
var EndpointGuilds = Endpoint + "guilds/"
View Source
var EndpointInvites = Endpoint + "invites/"
View Source
var EndpointWebhooks = Endpoint + "webhooks/"
View Source
var ErrEmptyMessage = errors.New("message is empty")

ErrEmptyMessage is returned if either a SendMessageData or an ExecuteWebhookData has both an empty Content and no Embed(s).

View Source
var ErrInvalidImageCT = errors.New("unknown image content-type")
View Source
var ErrInvalidImageData = errors.New("invalid image data")
View Source
var UserAgent = "DiscordBot (https://github.com/diamondburned/arikawa, v0.0.1)"

Functions

This section is empty.

Types

type Ack added in v0.1.5

type Ack struct {
	Token string `json:"token"`
}

Ack is the read state of a channel. This is undocumented.

type AddMemberData added in v0.7.0

type AddMemberData struct {
	// Token is an oauth2 access token granted with the guilds.join to the
	// bot's application for the user you want to add to the guild.
	Token string `json:"access_token"`
	// Nick is the value to set users nickname to.
	//
	// Requires MANAGE_NICKNAMES.
	Nick option.String `json:"nick,omitempty"`
	// Roles is an array of role ids the member is assigned.
	//
	// Requires MANAGE_ROLES.
	Roles *[]discord.RoleID `json:"roles,omitempty"`
	// Mute specifies whether the user is muted in voice channels.
	//
	// Requires MUTE_MEMBERS.
	Mute option.Bool `json:"mute,omitempty"`
	// Deaf specifies whether the user is deafened in voice channels.
	//
	// Requires DEAFEN_MEMBERS.
	Deaf option.Bool `json:"deaf,omitempty"`
}

https://discord.com/developers/docs/resources/guild#add-guild-member-json-params

type AllowedMentionType added in v0.4.1

type AllowedMentionType string

AllowedMentionType is a constant that tells Discord what is allowed to parse from a message content. This can help prevent things such as an unintentional @everyone mention.

const (
	// AllowRoleMention makes Discord parse roles in the content.
	AllowRoleMention AllowedMentionType = "roles"
	// AllowUserMention makes Discord parse user mentions in the content.
	AllowUserMention AllowedMentionType = "users"
	// AllowEveryoneMention makes Discord parse @everyone mentions.
	AllowEveryoneMention AllowedMentionType = "everyone"
)

type AllowedMentions added in v0.4.1

type AllowedMentions struct {
	// Parse is an array of allowed mention types to parse from the content.
	Parse []AllowedMentionType `json:"parse"`
	// Roles is an array of role_ids to mention (Max size of 100).
	Roles []discord.RoleID `json:"roles,omitempty"`
	// Users is an array of user_ids to mention (Max size of 100).
	Users []discord.UserID `json:"users,omitempty"`
}

AllowedMentions is a whitelist of mentions for a message. https://discordapp.com/developers/docs/resources/channel#allowed-mentions-object

Whitelists

Roles and Users are slices that act as whitelists for IDs that are allowed to be mentioned. For example, if only 1 ID is provided in Users, then only that ID will be parsed in the message. No other IDs will be. The same example also applies for roles.

If Parse is an empty slice and both Users and Roles are empty slices, then no mentions will be parsed.

Constraints

If the Users slice is not empty, then Parse must not have AllowUserMention. Likewise, if the Roles slice is not empty, then Parse must not have AllowRoleMention. This is because everything provided in Parse will make Discord parse it completely, meaning they would be mutually exclusive with whitelist slices, Roles and Users.

func (AllowedMentions) Verify added in v0.4.1

func (am AllowedMentions) Verify() error

Verify checks the AllowedMentions against constraints mentioned in AllowedMentions' documentation. This will be called on SendMessageComplex.

type AuditLogData added in v0.6.3

type AuditLogData struct {
	// UserID filters the log for actions made by a user.
	UserID discord.UserID `schema:"user_id,omitempty"`
	// ActionType is the type of audit log event.
	ActionType discord.AuditLogEvent `schema:"action_type,omitempty"`
	// Before filters the log before a certain entry ID.
	Before discord.AuditLogEntryID `schema:"before,omitempty"`
	// Limit limits how many entries are returned (default 50, minimum 1,
	// maximum 100).
	Limit uint `schema:"limit"`
}

https://discord.com/developers/docs/resources/audit-log#get-guild-audit-log-query-string-parameters

type BanData added in v0.7.0

type BanData struct {
	// DeleteDays is the number of days to delete messages for (0-7).
	DeleteDays option.Uint `schema:"delete_message_days,omitempty"`
	// Reason is the reason for the ban.
	Reason option.String `schema:"reason,omitempty"`
}

https://discord.com/developers/docs/resources/guild#create-guild-ban-query-string-params

type Client

type Client struct {
	*httputil.Client
	Session
}

func NewClient

func NewClient(token string) *Client

func NewCustomClient added in v0.4.0

func NewCustomClient(token string, httpClient *httputil.Client) *Client

func (*Client) Ack added in v0.1.5

func (c *Client) Ack(channelID discord.ChannelID, messageID discord.MessageID, ack *Ack) error

Ack marks the read state of a channel. This is undocumented. The method will write to the ack variable passed in. If this method is called asynchronously, then ack should be mutex guarded.

func (*Client) AddMember

func (c *Client) AddMember(
	guildID discord.GuildID, userID discord.UserID, data AddMemberData) (*discord.Member, error)

AddMember adds a user to the guild, provided you have a valid oauth2 access token for the user with the guilds.join scope. Returns a 201 Created with the guild member as the body, or 204 No Content if the user is already a member of the guild.

Fires a Guild Member Add Gateway event.

The Authorization header must be a Bot token (belonging to the same application used for authorization), and the bot must be a member of the guild with CREATE_INSTANT_INVITE permission.

func (*Client) AddRecipient

func (c *Client) AddRecipient(channelID discord.ChannelID, userID discord.UserID, accessToken, nickname string) error

AddRecipient adds a user to a group direct message. As accessToken is needed, clearly this endpoint should only be used for OAuth. AccessToken can be obtained with the "gdm.join" scope.

func (*Client) AddRole

func (c *Client) AddRole(guildID discord.GuildID, userID discord.UserID, roleID discord.RoleID) error

Adds a role to a guild member.

Requires the MANAGE_ROLES permission.

func (*Client) AttachIntegration

func (c *Client) AttachIntegration(
	guildID discord.GuildID, integrationID discord.IntegrationID,
	integrationType discord.Service) error

AttachIntegration attaches an integration object from the current user to the guild.

Requires the MANAGE_GUILD permission. Fires a Guild Integrations Update Gateway event.

func (*Client) AuditLog added in v0.6.3

func (c *Client) AuditLog(guildID discord.GuildID, data AuditLogData) (*discord.AuditLog, error)

AuditLog returns an audit log object for the guild.

Requires the VIEW_AUDIT_LOG permission.

func (*Client) Ban

func (c *Client) Ban(guildID discord.GuildID, userID discord.UserID, data BanData) error

Ban creates a guild ban, and optionally delete previous messages sent by the banned user.

Requires the BAN_MEMBERS permission.

func (*Client) Bans

func (c *Client) Bans(guildID discord.GuildID) ([]discord.Ban, error)

Bans returns a list of ban objects for the users banned from this guild.

Requires the BAN_MEMBERS permission.

func (*Client) ChangeOwnNickname

func (c *Client) ChangeOwnNickname(
	guildID discord.GuildID, nick string) error

ChangeOwnNickname modifies the nickname of the current user in a guild.

Fires a Guild Member Update Gateway event.

func (*Client) Channel

func (c *Client) Channel(channelID discord.ChannelID) (*discord.Channel, error)

Channel gets a channel by ID. Returns a channel object.

func (*Client) ChannelInvites

func (c *Client) ChannelInvites(channelID discord.ChannelID) ([]discord.Invite, error)

ChannelInvites returns a list of invite objects (with invite metadata) for the channel. Only usable for guild channels.

Requires the MANAGE_CHANNELS permission.

func (*Client) ChannelWebhooks added in v0.7.0

func (c *Client) ChannelWebhooks(channelID discord.ChannelID) ([]discord.Webhook, error)

ChannelWebhooks returns the webhooks of the channel with the given ID.

Requires the MANAGE_WEBHOOKS permission.

func (*Client) Channels

func (c *Client) Channels(guildID discord.GuildID) ([]discord.Channel, error)

Channels returns a list of guild channel objects.

func (*Client) CreateChannel

func (c *Client) CreateChannel(
	guildID discord.GuildID, data CreateChannelData) (*discord.Channel, error)

CreateChannel creates a new channel object for the guild.

Requires the MANAGE_CHANNELS permission. Fires a Channel Create Gateway event.

func (*Client) CreateEmoji

func (c *Client) CreateEmoji(guildID discord.GuildID, data CreateEmojiData) (*discord.Emoji, error)

CreateEmoji creates a new emoji in the guild. This endpoint requires MANAGE_EMOJIS. ContentType must be "image/jpeg", "image/png", or "image/gif". However, ContentType can also be automatically detected (though shouldn't be relied on). Emojis and animated emojis have a maximum file size of 256kb.

func (*Client) CreateGuild

func (c *Client) CreateGuild(data CreateGuildData) (*discord.Guild, error)

CreateGuild creates a new guild. Returns a guild object on success. Fires a Guild Create Gateway event.

This endpoint can be used only by bots in less than 10 guilds.

func (*Client) CreateInvite

func (c *Client) CreateInvite(
	channelID discord.ChannelID, data CreateInviteData) (*discord.Invite, error)

CreateInvite creates a new invite object for the channel. Only usable for guild channels.

Requires the CREATE_INSTANT_INVITE permission.

func (*Client) CreatePrivateChannel

func (c *Client) CreatePrivateChannel(recipientID discord.UserID) (*discord.Channel, error)

CreatePrivateChannel creates a new DM channel with a user.

func (*Client) CreateRole

func (c *Client) CreateRole(guildID discord.GuildID, data CreateRoleData) (*discord.Role, error)

CreateRole creates a new role for the guild.

Requires the MANAGE_ROLES permission. Fires a Guild Role Create Gateway event.

func (*Client) CreateWebhook

func (c *Client) CreateWebhook(
	channelID discord.ChannelID, data CreateWebhookData) (*discord.Webhook, error)

CreateWebhook creates a new webhook.

Webhooks cannot be named "clyde".

Requires the MANAGE_WEBHOOKS permission.

func (*Client) DeleteAllReactions

func (c *Client) DeleteAllReactions(channelID discord.ChannelID, messageID discord.MessageID) error

DeleteAllReactions deletes all reactions on a message.

This endpoint requires the MANAGE_MESSAGES permission to be present on the current user. Fires a Message Reaction Remove All Gateway event.

func (*Client) DeleteChannel

func (c *Client) DeleteChannel(channelID discord.ChannelID) error

DeleteChannel deletes a channel, or closes a private message. Requires the MANAGE_CHANNELS permission for the guild. Deleting a category does not delete its child channels: they will have their parent_id removed and a Channel Update Gateway event will fire for each of them.

Fires a Channel Delete Gateway event.

func (*Client) DeleteChannelPermission

func (c *Client) DeleteChannelPermission(channelID discord.ChannelID, overwriteID discord.Snowflake) error

DeleteChannelPermission deletes a channel permission overwrite for a user or role in a channel. Only usable for guild channels.

Requires the MANAGE_ROLES permission.

func (*Client) DeleteEmoji

func (c *Client) DeleteEmoji(guildID discord.GuildID, emojiID discord.EmojiID) error

Delete the given emoji.

Requires the MANAGE_EMOJIS permission. Fires a Guild Emojis Update Gateway event.

func (*Client) DeleteGuild

func (c *Client) DeleteGuild(id discord.GuildID) error

DeleteGuild deletes a guild permanently. The User must be owner.

Fires a Guild Delete Gateway event.

func (*Client) DeleteInvite

func (c *Client) DeleteInvite(code string) (*discord.Invite, error)

DeleteInvite deletes an invite.

Requires the MANAGE_CHANNELS permission on the channel this invite belongs to, or MANAGE_GUILD to remove any invite across the guild. Fires a Invite Delete Gateway event.

func (*Client) DeleteMessage

func (c *Client) DeleteMessage(channelID discord.ChannelID, messageID discord.MessageID) error

DeleteMessage delete a message. If operating on a guild channel and trying to delete a message that was not sent by the current user, this endpoint requires the MANAGE_MESSAGES permission.

func (*Client) DeleteMessages

func (c *Client) DeleteMessages(channelID discord.ChannelID, messageIDs []discord.MessageID) error

DeleteMessages deletes multiple messages in a single request. This endpoint can only be used on guild channels and requires the MANAGE_MESSAGES permission. This endpoint only works for bots.

This endpoint will not delete messages older than 2 weeks, and will fail if any message provided is older than that or if any duplicate message IDs are provided.

Fires a Message Delete Bulk Gateway event.

func (*Client) DeleteReactions added in v0.0.9

func (c *Client) DeleteReactions(
	channelID discord.ChannelID, messageID discord.MessageID, emoji Emoji) error

DeleteReactions deletes all the reactions for a given emoji on a message.

This endpoint requires the MANAGE_MESSAGES permission to be present on the current user. Fires a Message Reaction Remove Emoji Gateway event.

func (*Client) DeleteRelationship added in v0.10.5

func (c *Client) DeleteRelationship(userID discord.UserID) error

DeleteRelationship deletes the relationship between the current user and the given user.

func (*Client) DeleteRole

func (c *Client) DeleteRole(guildID discord.GuildID, roleID discord.RoleID) error

DeleteRole deletes a guild role.

Requires the MANAGE_ROLES permission.

func (*Client) DeleteUserReaction added in v0.0.9

func (c *Client) DeleteUserReaction(
	channelID discord.ChannelID, messageID discord.MessageID, userID discord.UserID, emoji Emoji) error

DeleteReaction deletes another user's reaction.

This endpoint requires the MANAGE_MESSAGES permission to be present on the current user.

func (*Client) DeleteWebhook

func (c *Client) DeleteWebhook(webhookID discord.WebhookID) error

DeleteWebhook deletes a webhook permanently.

Requires the MANAGE_WEBHOOKS permission.

func (*Client) EditChannelPermission

func (c *Client) EditChannelPermission(
	channelID discord.ChannelID, overwriteID discord.Snowflake, data EditChannelPermissionData) error

EditChannelPermission edits the channel's permission overwrites for a user or role in a channel. Only usable for guild channels.

Requires the MANAGE_ROLES permission.

func (*Client) EditEmbed added in v0.8.1

func (c *Client) EditEmbed(
	channelID discord.ChannelID, messageID discord.MessageID, embed discord.Embed) (*discord.Message, error)

EditEmbed edits the embed of a previously sent message. For more documentation, refer to EditMessageComplex.

func (*Client) EditMessage

func (c *Client) EditMessage(
	channelID discord.ChannelID, messageID discord.MessageID, content string,
	embed *discord.Embed, suppressEmbeds bool) (*discord.Message, error)

EditMessage edits a previously sent message. For more documentation, refer to EditMessageComplex.

func (*Client) EditMessageComplex added in v0.7.1

func (c *Client) EditMessageComplex(
	channelID discord.ChannelID, messageID discord.MessageID, data EditMessageData) (*discord.Message, error)

EditMessageComplex edits a previously sent message. The fields Content, Embed, AllowedMentions and Flags can be edited by the original message author. Other users can only edit flags and only if they have the MANAGE_MESSAGES permission in the corresponding channel. When specifying flags, ensure to include all previously set flags/bits in addition to ones that you are modifying. Only flags documented in EditMessageData may be modified by users (unsupported flag changes are currently ignored without error).

Fires a Message Update Gateway event.

func (*Client) EditText added in v0.8.1

func (c *Client) EditText(
	channelID discord.ChannelID, messageID discord.MessageID, content string) (*discord.Message, error)

EditText edits the contents of a previously sent message. For more documentation, refer to EditMessageComplex.

func (*Client) Emoji

func (c *Client) Emoji(guildID discord.GuildID, emojiID discord.EmojiID) (*discord.Emoji, error)

Emoji returns an emoji object for the given guild and emoji IDs.

func (*Client) Emojis

func (c *Client) Emojis(guildID discord.GuildID) ([]discord.Emoji, error)

Emojis returns a list of emoji objects for the given guild.

func (*Client) GetBan

func (c *Client) GetBan(guildID discord.GuildID, userID discord.UserID) (*discord.Ban, error)

GetBan returns a ban object for the given user.

Requires the BAN_MEMBERS permission.

func (*Client) Guild

func (c *Client) Guild(id discord.GuildID) (*discord.Guild, error)

Guild returns the guild object for the given id. ApproximateMembers and ApproximatePresences will not be set.

func (*Client) GuildImage

func (c *Client) GuildImage(guildID discord.GuildID, img GuildImageStyle) (io.ReadCloser, error)

GuildImage returns a PNG image widget for the guild. Requires no permissions or authentication.

func (*Client) GuildImageURL

func (c *Client) GuildImageURL(guildID discord.GuildID, img GuildImageStyle) string

GuildImageURL returns a link to the PNG image widget for the guild.

Requires no permissions or authentication.

func (*Client) GuildInvites

func (c *Client) GuildInvites(guildID discord.GuildID) ([]discord.Invite, error)

GuildInvites returns a list of invite objects (with invite metadata) for the guild.

Requires the MANAGE_GUILD permission.

func (*Client) GuildPreview added in v0.8.1

func (c *Client) GuildPreview(id discord.GuildID) (*discord.GuildPreview, error)

GuildPreview returns the guild preview object for the given id, even if the user is not in the guild.

This endpoint is only for public guilds.

func (*Client) GuildVanityURL

func (c *Client) GuildVanityURL(guildID discord.GuildID) (*discord.Invite, error)

GuildVanityURL returns *Invite for guilds that have that feature enabled, but only Code and Uses are filled. Code will be "" if a vanity url for the guild is not set.

Requires MANAGE_GUILD.

func (*Client) GuildWebhooks added in v0.7.0

func (c *Client) GuildWebhooks(guildID discord.GuildID) ([]discord.Webhook, error)

GuildWebhooks returns the webhooks of the guild with the given ID.

Requires the MANAGE_WEBHOOKS permission.

func (*Client) GuildWidget added in v0.8.2

func (c *Client) GuildWidget(guildID discord.GuildID) (*discord.GuildWidget, error)

GuildWidget returns the guild widget object.

Requires the MANAGE_GUILD permission.

func (*Client) GuildWithCount added in v0.7.0

func (c *Client) GuildWithCount(id discord.GuildID) (*discord.Guild, error)

GuildWithCount returns the guild object for the given id. This will also set the ApproximateMembers and ApproximatePresences fields of the guild struct.

func (*Client) Guilds

func (c *Client) Guilds(limit uint) ([]discord.Guild, error)

Guilds returns a list of partial guild objects the current user is a member of. This method automatically paginates until it reaches the passed limit, or, if the limit is set to 0, has fetched all guilds the user has joined.

As the underlying endpoint has a maximum of 100 guilds per request, at maximum a total of limit/100 rounded up requests will be made, although they may be less, if no more guilds are available.

When fetching the guilds, those with the smallest ID will be fetched first.

Also note that 100 is the maximum number of guilds a non-bot user can join. Therefore, pagination is not needed for integrations that need to get a list of the users' guilds.

Requires the guilds OAuth2 scope.

func (*Client) GuildsAfter

func (c *Client) GuildsAfter(after discord.GuildID, limit uint) ([]discord.Guild, error)

GuildsAfter returns a list of partial guild objects the current user is a member of. This method automatically paginates until it reaches the passed limit, or, if the limit is set to 0, has fetched all guilds with an id higher than after.

As the underlying endpoint has a maximum of 100 guilds per request, at maximum a total of limit/100 rounded up requests will be made, although they may be less, if no more guilds are available.

Requires the guilds OAuth2 scope.

func (*Client) GuildsBefore

func (c *Client) GuildsBefore(before discord.GuildID, limit uint) ([]discord.Guild, error)

GuildsBefore returns a list of partial guild objects the current user is a member of. This method automatically paginates until it reaches the passed limit, or, if the limit is set to 0, has fetched all guilds with an id smaller than before.

As the underlying endpoint has a maximum of 100 guilds per request, at maximum a total of limit/100 rounded up requests will be made, although they may be less, if no more guilds are available.

Requires the guilds OAuth2 scope.

func (*Client) Integrations

func (c *Client) Integrations(guildID discord.GuildID) ([]discord.Integration, error)

Integrations returns a list of integration objects for the guild.

Requires the MANAGE_GUILD permission.

func (*Client) Invite

func (c *Client) Invite(code string) (*discord.Invite, error)

Invite returns an invite object for the given code.

ApproxMembers will not get filled.

func (*Client) InviteWithCounts added in v0.7.0

func (c *Client) InviteWithCounts(code string) (*discord.Invite, error)

Invite returns an invite object for the given code and fills ApproxMembers.

func (*Client) Kick

func (c *Client) Kick(guildID discord.GuildID, userID discord.UserID) error

Kick removes a member from a guild.

Requires KICK_MEMBERS permission. Fires a Guild Member Remove Gateway event.

func (*Client) KickWithReason added in v1.3.1

func (c *Client) KickWithReason(
	guildID discord.GuildID, userID discord.UserID, reason string) error

KickWithReason removes a member from a guild. The reason, if non-empty, will be displayed in the audit log of the guild.

Requires KICK_MEMBERS permission. Fires a Guild Member Remove Gateway event.

func (*Client) LeaveGuild

func (c *Client) LeaveGuild(id discord.GuildID) error

LeaveGuild leaves a guild.

func (*Client) Login added in v0.0.2

func (c *Client) Login(email, password string) (*LoginResponse, error)

func (*Client) Me

func (c *Client) Me() (*discord.User, error)

Me returns the user object of the requester's account. For OAuth2, this requires the identify scope, which will return the object without an email, and optionally the email scope, which returns the object with an email.

func (*Client) Member

func (c *Client) Member(guildID discord.GuildID, userID discord.UserID) (*discord.Member, error)

Member returns a guild member object for the specified user.

func (*Client) Members

func (c *Client) Members(guildID discord.GuildID, limit uint) ([]discord.Member, error)

Members returns a list of members of the guild with the passed id. This method automatically paginates until it reaches the passed limit, or, if the limit is set to 0, has fetched all members in the guild.

As the underlying endpoint has a maximum of 1000 members per request, at maximum a total of limit/1000 rounded up requests will be made, although they may be less if no more members are available.

When fetching the members, those with the smallest ID will be fetched first.

func (*Client) MembersAfter

func (c *Client) MembersAfter(
	guildID discord.GuildID, after discord.UserID, limit uint) ([]discord.Member, error)

MembersAfter returns a list of members of the guild with the passed id. This method automatically paginates until it reaches the passed limit, or, if the limit is set to 0, has fetched all members with an id higher than after.

As the underlying endpoint has a maximum of 1000 members per request, at maximum a total of limit/1000 rounded up requests will be made, although they may be less, if no more members are available.

func (*Client) Message

func (c *Client) Message(channelID discord.ChannelID, messageID discord.MessageID) (*discord.Message, error)

Message returns a specific message in the channel.

If operating on a guild channel, this endpoint requires the READ_MESSAGE_HISTORY permission to be present on the current user.

func (*Client) Messages

func (c *Client) Messages(channelID discord.ChannelID, limit uint) ([]discord.Message, error)

Messages returns a slice filled with the most recent messages sent in the channel with the passed ID. The method automatically paginates until it reaches the passed limit, or, if the limit is set to 0, has fetched all messages in the channel.

As the underlying endpoint is capped at a maximum of 100 messages per request, at maximum a total of limit/100 rounded up requests will be made, although they may be less, if no more messages are available.

When fetching the messages, those with the highest ID, will be fetched first. The returned slice will be sorted from latest to oldest.

func (*Client) MessagesAfter

func (c *Client) MessagesAfter(
	channelID discord.ChannelID, after discord.MessageID, limit uint) ([]discord.Message, error)

MessagesAfter returns a slice filled with the messages sent in the channel with the passed ID. The method automatically paginates until it reaches the passed limit, or, if the limit is set to 0, has fetched all messages in the channel with an id higher than after.

As the underlying endpoint has a maximum of 100 messages per request, at maximum a total of limit/100 rounded up requests will be made, although they may be less, if no more messages are available.

The returned slice will be sorted from latest to oldest.

func (*Client) MessagesAround

func (c *Client) MessagesAround(
	channelID discord.ChannelID, around discord.MessageID, limit uint) ([]discord.Message, error)

MessagesAround returns messages around the ID, with a limit of 100.

func (*Client) MessagesBefore

func (c *Client) MessagesBefore(
	channelID discord.ChannelID, before discord.MessageID, limit uint) ([]discord.Message, error)

MessagesBefore returns a slice filled with the messages sent in the channel with the passed id. The method automatically paginates until it reaches the passed limit, or, if the limit is set to 0, has fetched all messages in the channel with an id smaller than before.

As the underlying endpoint has a maximum of 100 messages per request, at maximum a total of limit/100 rounded up requests will be made, although they may be less, if no more messages are available.

The returned slice will be sorted from latest to oldest.

func (*Client) ModifyChannel

func (c *Client) ModifyChannel(channelID discord.ChannelID, data ModifyChannelData) error

ModifyChannel updates a channel's settings.

Requires the MANAGE_CHANNELS permission for the guild.

func (*Client) ModifyEmoji

func (c *Client) ModifyEmoji(guildID discord.GuildID, emojiID discord.EmojiID, data ModifyEmojiData) error

ModifyEmoji changes an existing emoji. This requires MANAGE_EMOJIS. Name and roles are optional fields (though you'd want to change either though).

Fires a Guild Emojis Update Gateway event.

func (*Client) ModifyGuild

func (c *Client) ModifyGuild(id discord.GuildID, data ModifyGuildData) (*discord.Guild, error)

ModifyGuild modifies a guild's settings. Requires the MANAGE_GUILD permission. Fires a Guild Update Gateway event.

func (*Client) ModifyGuildWidget added in v0.8.2

func (c *Client) ModifyGuildWidget(
	guildID discord.GuildID, data ModifyGuildWidgetData) (*discord.GuildWidget, error)

ModifyGuildWidget modifies a guild widget object for the guild.

Requires the MANAGE_GUILD permission.

func (*Client) ModifyIntegration

func (c *Client) ModifyIntegration(
	guildID discord.GuildID, integrationID discord.IntegrationID, data ModifyIntegrationData) error

ModifyIntegration modifies the behavior and settings of an integration object for the guild.

Requires the MANAGE_GUILD permission. Fires a Guild Integrations Update Gateway event.

func (*Client) ModifyMe

func (c *Client) ModifyMe(data ModifySelfData) (*discord.User, error)

ModifyMe modifies the requester's user account settings.

func (*Client) ModifyMember

func (c *Client) ModifyMember(guildID discord.GuildID, userID discord.UserID, data ModifyMemberData) error

ModifyMember modifies attributes of a guild member. If the channel_id is set to null, this will force the target user to be disconnected from voice.

Fires a Guild Member Update Gateway event.

func (*Client) ModifyRole

func (c *Client) ModifyRole(
	guildID discord.GuildID, roleID discord.RoleID,
	data ModifyRoleData) (*discord.Role, error)

ModifyRole modifies a guild role.

Requires the MANAGE_ROLES permission.

func (*Client) ModifyWebhook

func (c *Client) ModifyWebhook(
	webhookID discord.WebhookID, data ModifyWebhookData) (*discord.Webhook, error)

ModifyWebhook modifies a webhook.

Requires the MANAGE_WEBHOOKS permission.

func (*Client) MoveChannel

func (c *Client) MoveChannel(guildID discord.GuildID, data []MoveChannelData) error

MoveChannel modifies the position of channels in the guild.

Requires MANAGE_CHANNELS.

func (*Client) MoveRole

func (c *Client) MoveRole(guildID discord.GuildID, data []MoveRoleData) ([]discord.Role, error)

MoveRole modifies the positions of a set of role objects for the guild.

Requires the MANAGE_ROLES permission. Fires multiple Guild Role Update Gateway events.

func (*Client) PinMessage

func (c *Client) PinMessage(channelID discord.ChannelID, messageID discord.MessageID) error

PinMessage pins a message in a channel.

Requires the MANAGE_MESSAGES permission.

func (*Client) PinnedMessages

func (c *Client) PinnedMessages(channelID discord.ChannelID) ([]discord.Message, error)

PinnedMessages returns all pinned messages in the channel as an array of message objects.

func (*Client) PrivateChannels

func (c *Client) PrivateChannels() ([]discord.Channel, error)

PrivateChannels returns a list of DM channel objects. For bots, this is no longer a supported method of getting recent DMs, and will return an empty array.

func (*Client) Prune

func (c *Client) Prune(guildID discord.GuildID, data PruneData) (uint, error)

Prune begins a prune. Days must be 1 or more, default 7.

By default, prune will not remove users with roles. You can optionally include specific roles in your prune by providing the IncludedRoles parameter. Any inactive user that has a subset of the provided role(s) will be included in the prune and users with additional roles will not.

Requires KICK_MEMBERS. Fires multiple Guild Member Remove Gateway events.

func (*Client) PruneCount

func (c *Client) PruneCount(guildID discord.GuildID, data PruneCountData) (uint, error)

PruneCount returns the number of members that would be removed in a prune operation. Days must be 1 or more, default 7.

By default, prune will not remove users with roles. You can optionally include specific roles in your prune by providing the IncludedRoles parameter. Any inactive user that has a subset of the provided role(s) will be counted in the prune and users with additional roles will not.

Requires KICK_MEMBERS.

func (*Client) React

func (c *Client) React(channelID discord.ChannelID, messageID discord.MessageID, emoji Emoji) error

React creates a reaction for the message.

This endpoint requires the READ_MESSAGE_HISTORY permission to be present on the current user. Additionally, if nobody else has reacted to the message using this emoji, this endpoint requires the 'ADD_REACTIONS' permission to be present on the current user.

func (*Client) Reactions

func (c *Client) Reactions(
	channelID discord.ChannelID, messageID discord.MessageID, emoji Emoji, limit uint) ([]discord.User, error)

Reactions returns a list of users that reacted with the passed Emoji. This method automatically paginates until it reaches the passed limit, or, if the limit is set to 0, has fetched all users within the passed range.

As the underlying endpoint has a maximum of 100 users per request, at maximum a total of limit/100 rounded up requests will be made, although they may be less, if no more guilds are available.

When fetching the users, those with the smallest ID will be fetched first.

func (*Client) ReactionsAfter

func (c *Client) ReactionsAfter(
	channelID discord.ChannelID, messageID discord.MessageID, after discord.UserID, emoji Emoji,
	limit uint) ([]discord.User, error)

ReactionsAfter returns a list of users that reacted with the passed Emoji. This method automatically paginates until it reaches the passed limit, or, if the limit is set to 0, has fetched all users with an id higher than after.

As the underlying endpoint has a maximum of 100 users per request, at maximum a total of limit/100 rounded up requests will be made, although they may be less, if no more guilds are available.

func (*Client) ReactionsBefore

func (c *Client) ReactionsBefore(
	channelID discord.ChannelID, messageID discord.MessageID, before discord.UserID, emoji Emoji,
	limit uint) ([]discord.User, error)

ReactionsBefore returns a list of users that reacted with the passed Emoji. This method automatically paginates until it reaches the passed limit, or, if the limit is set to 0, has fetched all users with an id smaller than before.

As the underlying endpoint has a maximum of 100 users per request, at maximum a total of limit/100 rounded up requests will be made, although they may be less, if no more guilds are available.

func (*Client) RemoveRecipient

func (c *Client) RemoveRecipient(channelID discord.ChannelID, userID discord.UserID) error

RemoveRecipient removes a user from a group direct message.

func (*Client) RemoveRole

func (c *Client) RemoveRole(guildID discord.GuildID, userID discord.UserID, roleID discord.RoleID) error

RemoveRole removes a role from a guild member.

Requires the MANAGE_ROLES permission. Fires a Guild Member Update Gateway event.

func (*Client) Roles

func (c *Client) Roles(guildID discord.GuildID) ([]discord.Role, error)

Roles returns a list of role objects for the guild.

func (*Client) SendEmbed added in v0.7.0

func (c *Client) SendEmbed(
	channelID discord.ChannelID, e discord.Embed) (*discord.Message, error)

SendEmbed posts an Embed to a guild text or DM channel.

If operating on a guild channel, this endpoint requires the SEND_MESSAGES permission to be present on the current user.

Fires a Message Create Gateway event.

func (*Client) SendMessage

func (c *Client) SendMessage(
	channelID discord.ChannelID, content string, embed *discord.Embed) (*discord.Message, error)

SendMessage posts a message to a guild text or DM channel.

If operating on a guild channel, this endpoint requires the SEND_MESSAGES permission to be present on the current user.

Fires a Message Create Gateway event.

func (*Client) SendMessageComplex

func (c *Client) SendMessageComplex(
	channelID discord.ChannelID, data SendMessageData) (*discord.Message, error)

SendMessageComplex posts a message to a guild text or DM channel. If operating on a guild channel, this endpoint requires the SEND_MESSAGES permission to be present on the current user. If the tts field is set to true, the SEND_TTS_MESSAGES permission is required for the message to be spoken. Returns a message object. Fires a Message Create Gateway event.

The maximum request size when sending a message is 8MB.

This endpoint supports requests with Content-Types of both application/json and multipart/form-data. You must however use multipart/form-data when uploading files. Note that when sending multipart/form-data requests the embed field cannot be used, however you can pass a JSON encoded body as form value for payload_json, where additional request parameters such as embed can be set.

Note that when sending application/json you must send at least one of content or embed, and when sending multipart/form-data, you must send at least one of content, embed or file. For a file attachment, the Content-Disposition subpart header MUST contain a filename parameter.

func (*Client) SendText added in v0.7.0

func (c *Client) SendText(channelID discord.ChannelID, content string) (*discord.Message, error)

SendText posts a only-text message to a guild text or DM channel.

If operating on a guild channel, this endpoint requires the SEND_MESSAGES permission to be present on the current user.

Fires a Message Create Gateway event.

func (*Client) SetNote added in v0.10.2

func (c *Client) SetNote(userID discord.UserID, note string) error

SetNote sets a note for the user. This endpoint is undocumented and might only work for user accounts.

func (*Client) SetRelationship added in v0.10.5

func (c *Client) SetRelationship(userID discord.UserID, t discord.RelationshipType) error

SetRelationship sets the relationship type between the current user and the given user.

func (*Client) SyncIntegration

func (c *Client) SyncIntegration(guildID discord.GuildID, integrationID discord.IntegrationID) error

Sync an integration. Requires the MANAGE_GUILD permission.

func (*Client) TOTP added in v0.0.2

func (c *Client) TOTP(code, ticket string) (*LoginResponse, error)

func (*Client) Typing

func (c *Client) Typing(channelID discord.ChannelID) error

Typing posts a typing indicator to the channel. Undocumented, but the client usually clears the typing indicator after 8-10 seconds (or after a message).

func (*Client) Unban

func (c *Client) Unban(guildID discord.GuildID, userID discord.UserID) error

Unban removes the ban for a user.

Requires the BAN_MEMBERS permissions. Fires a Guild Ban Remove Gateway event.

func (*Client) UnpinMessage

func (c *Client) UnpinMessage(channelID discord.ChannelID, messageID discord.MessageID) error

UnpinMessage deletes a pinned message in a channel.

Requires the MANAGE_MESSAGES permission.

func (*Client) Unreact added in v0.0.9

func (c *Client) Unreact(chID discord.ChannelID, msgID discord.MessageID, emoji Emoji) error

Unreact removes a reaction the current user has made for the message.

func (*Client) User

func (c *Client) User(userID discord.UserID) (*discord.User, error)

User returns a user object for a given user ID.

func (*Client) UserConnections added in v0.8.1

func (c *Client) UserConnections() ([]discord.Connection, error)

UserConnections returns a list of connection objects. Requires the connections OAuth2 scope.

func (*Client) VoiceRegionsGuild

func (c *Client) VoiceRegionsGuild(guildID discord.GuildID) ([]discord.VoiceRegion, error)

GuildVoiceRegions is the same as /voice, but returns VIP ones as well if available.

func (*Client) Webhook

func (c *Client) Webhook(webhookID discord.WebhookID) (*discord.Webhook, error)

Webhook returns the webhook with the given id.

func (*Client) WithContext added in v0.6.0

func (c *Client) WithContext(ctx context.Context) *Client

WithContext returns a shallow copy of Client with the given context. It's used for method timeouts and such. This method is thread-safe.

type CreateChannelData

type CreateChannelData struct {
	// Name is the channel name (2-100 characters).
	//
	// Channel Type: All
	Name string `json:"name"`
	// Type is the type of channel.
	//
	// Channel Type: All
	Type discord.ChannelType `json:"type,omitempty"`
	// Topic is the channel topic (0-1024 characters).
	//
	// Channel Types: Text, News
	Topic string `json:"topic,omitempty"`
	// VoiceBitrate is the bitrate (in bits) of the voice channel.
	// 8000 to 96000 (128000 for VIP servers)
	//
	// Channel Types: Voice
	VoiceBitrate uint `json:"bitrate,omitempty"`
	// VoiceUserLimit is the user limit of the voice channel.
	// 0 refers to no limit, 1 to 99 refers to a user limit.
	//
	// Channel Types: Voice
	VoiceUserLimit uint `json:"user_limit,omitempty"`
	// UserRateLimit is the amount of seconds a user has to wait before sending
	// another message (0-21600).
	// Bots, as well as users with the permission manage_messages or
	// manage_channel, are unaffected.
	//
	// Channel Types: Text
	UserRateLimit discord.Seconds `json:"rate_limit_per_user,omitempty"`
	// Position is the sorting position of the channel.
	//
	// Channel Types: All
	Position option.Int `json:"position,omitempty"`
	// Permissions are the channel's permission overwrites.
	//
	// Channel Types: All
	Permissions []discord.Overwrite `json:"permission_overwrites,omitempty"`
	// CategoryID is the 	id of the parent category for a channel.
	//
	// Channel Types: Text, News, Store, Voice
	CategoryID discord.ChannelID `json:"parent_id,string,omitempty"`
	// NSFW specifies whether the channel is nsfw.
	//
	// Channel Types: Text, News, Store.
	NSFW bool `json:"nsfw,omitempty"`
}

https://discord.com/developers/docs/resources/guild#create-guild-channel-json-params

type CreateEmojiData added in v0.7.0

type CreateEmojiData struct {
	// Name is the name of the emoji.
	Name string `json:"name"`
	// Image is the the 128x128 emoji image.
	Image Image `json:"image"`
	// Roles are the roles for which this emoji will be whitelisted.
	Roles *[]discord.RoleID `json:"roles,omitempty"`
}

https://discord.com/developers/docs/resources/emoji#create-guild-emoji-json-params

type CreateGuildData

type CreateGuildData struct {
	// Name is the 	name of the guild (2-100 characters)
	Name string `json:"name"`
	// VoiceRegion is the voice region id.
	VoiceRegion string `json:"region,omitempty"`
	// Icon is the base64 128x128 image for the guild icon.
	Icon *Image `json:"image,omitempty"`

	// Verification is the 	verification level.
	Verification *discord.Verification `json:"verification_level,omitempty"`
	// Notification is the 	default message notification level.
	Notification *discord.Notification `json:"default_message_notifications,omitempty"`
	// ExplicitFilter is the explicit content filter level.
	ExplicitFilter *discord.ExplicitFilter `json:"explicit_content_filter,omitempty"`

	// Roles are the new guild roles.
	//
	// When using the roles parameter, the first member of the array is used to
	// change properties of the guild's @everyone role. If you are trying to
	// bootstrap a guild with additional roles, keep this in mind.
	//
	// When using the roles parameter, the required id field within each role
	// object is an integer placeholder, and will be replaced by the API upon
	// consumption. Its purpose is to allow you to overwrite a role's
	// permissions in a channel when also passing in channels with the channels
	// array.
	Roles []discord.Role `json:"roles,omitempty"`
	// Channels are the new guild's channels.
	// Assigning a channel to a channel category is not supported by this
	// endpoint, i.e. a channel can't have the parent_id field.
	//
	// When using the channels parameter, the position field is ignored,
	// and none of the default channels are created.
	//
	// When using the channels parameter, the id field within each channel
	// object may be set to an integer placeholder, and will be replaced by the
	// API upon consumption. Its purpose is to allow you to create
	// GUILD_CATEGORY channels by setting the parent_id field on any children
	// to the category's id field. Category channels must be listed before any
	// children.
	Channels []discord.Channel `json:"channels,omitempty"`

	// AFKChannelID is the id for the afk channel.
	AFKChannelID discord.ChannelID `json:"afk_channel_id,omitempty"`
	// AFKTimeout is the afk timeout in seconds.
	AFKTimeout option.Seconds `json:"afk_timeout,omitempty"`

	// SystemChannelID is the id of the channel where guild notices such as
	// welcome messages and boost events are posted.
	SystemChannelID discord.ChannelID `json:"system_channel_id,omitempty"`
}

https://discordapp.com/developers/docs/resources/guild#create-guild-json-params

type CreateInviteData added in v0.7.0

type CreateInviteData struct {
	// MaxAge is the duration of invite in seconds before expiry, or 0 for
	// never.
	//
	// Default:	86400 (24 hours)
	MaxAge option.Uint `json:"max_age,omitempty"`
	// MaxUses is the max number of uses or 0 for unlimited.
	//
	// Default:	0
	MaxUses uint `json:"max_uses,omitempty"`
	// Temporary specifies whether this invite only grants temporary membership.
	//
	// Default:	false
	Temporary bool `json:"temporary,omitempty"`
	// Unique has the following behavior: if true, don't try to reuse a similar
	// invite (useful for creating many unique one time use invites).
	//
	// Default:	false
	Unique bool `json:"unique,omitempty"`
}

https://discord.com/developers/docs/resources/channel#create-channel-invite-json-params

type CreateRoleData added in v0.7.0

type CreateRoleData struct {
	// Name is the 	name of the role.
	//
	// Default: "new role"
	Name string `json:"name,omitempty"`
	// Permissions is the bitwise value of the enabled/disabled permissions.
	//
	// Default: @everyone permissions in guild
	Permissions discord.Permissions `json:"permissions,omitempty,string"`
	// Color is the RGB color value of the role.
	//
	// Default: 0
	Color discord.Color `json:"color,omitempty"`
	// Hoist specifies whether the role should be displayed separately in the
	// sidebar.
	//
	// Default: false
	Hoist bool `json:"hoist,omitempty"`
	// Mentionable specifies whether the role should be mentionable.
	//
	// Default: false
	Mentionable bool `json:"mentionable,omitempty"`
}

https://discord.com/developers/docs/resources/guild#create-guild-role-json-params

type CreateWebhookData added in v0.7.0

type CreateWebhookData struct {
	// Name is the name of the webhook (1-80 characters).
	Name string `json:"name"`
	// Avatar is the image for the default webhook avatar.
	Avatar *Image `json:"avatar"`
}

https://discord.com/developers/docs/resources/webhook#create-webhook-json-params

type EditChannelPermissionData added in v0.9.2

type EditChannelPermissionData struct {
	// Type is either "role" or "member".
	Type discord.OverwriteType `json:"type"`
	// Allow is a permission bit set for granted permissions.
	Allow discord.Permissions `json:"allow,string"`
	// Deny is a permission bit set for denied permissions.
	Deny discord.Permissions `json:"deny,string"`
}

https://discord.com/developers/docs/resources/channel#edit-channel-permissions-json-params

type EditMessageData added in v0.7.0

type EditMessageData struct {
	// Content is the new message contents (up to 2000 characters).
	Content option.NullableString `json:"content,omitempty"`
	// Embed contains embedded rich content.
	Embed *discord.Embed `json:"embed,omitempty"`
	// AllowedMentions are the allowed mentions for a message.
	AllowedMentions *AllowedMentions `json:"allowed_mentions,omitempty"`
	// Flags edits the flags of a message (only SUPPRESS_EMBEDS can currently
	// be set/unset)
	//
	// This field is nullable.
	Flags *discord.MessageFlags `json:"flags,omitempty"`
}

https://discord.com/developers/docs/resources/channel#edit-message-json-params

type Emoji added in v0.7.0

type Emoji = string

Emoji is the API format of a regular Emoji, both Unicode or custom. This could usually be formatted by calling (discord.Emoji).APIString().

func NewCustomEmoji added in v0.7.0

func NewCustomEmoji(id discord.EmojiID, name string) Emoji

NewCustomEmoji creates a new Emoji using a custom guild emoji as base. Unicode emojis should be directly passed to the function using Emoji.

type ErrImageTooLarge

type ErrImageTooLarge struct {
	Size, Max int
}

func (ErrImageTooLarge) Error

func (err ErrImageTooLarge) Error() string

type ExecuteWebhookData

type ExecuteWebhookData struct {
	// Content are the message contents (up to 2000 characters).
	//
	// Required: one of content, file, embeds
	Content string `json:"content,omitempty"`

	// Username overrides the default username of the webhook
	Username string `json:"username,omitempty"`
	// AvatarURL overrides the default avatar of the webhook.
	AvatarURL discord.URL `json:"avatar_url,omitempty"`

	// TTS is true if this is a TTS message.
	TTS bool `json:"tts,omitempty"`
	// Embeds contains embedded rich content.
	//
	// Required: one of content, file, embeds
	Embeds []discord.Embed `json:"embeds,omitempty"`

	Files []SendMessageFile `json:"-"`

	// AllowedMentions are the allowed mentions for the message.
	AllowedMentions *AllowedMentions `json:"allowed_mentions,omitempty"`
}

func (*ExecuteWebhookData) WriteMultipart

func (data *ExecuteWebhookData) WriteMultipart(body *multipart.Writer) error

type GuildImageStyle added in v0.7.0

type GuildImageStyle string

https://discord.com/developers/docs/resources/guild#get-guild-widget-image-widget-style-options

const (
	// GuildShield is a shield style widget with Discord icon and guild members
	// online count.
	//
	// Example: https://discordapp.com/api/guilds/81384788765712384/widget.png?style=shield
	GuildShield GuildImageStyle = "shield"
	// GuildBanner1 is a large image with guild icon, name and online count.
	// "POWERED BY DISCORD" as the footer of the widget.
	//
	// Example: https://discordapp.com/api/guilds/81384788765712384/widget.png?style=banner1
	GuildBanner1 GuildImageStyle = "banner1"
	// GuildBanner2 is a smaller widget style with guild icon, name and online
	// count. Split on the right with Discord logo.
	//
	// Example: https://discordapp.com/api/guilds/81384788765712384/widget.png?style=banner2
	GuildBanner2 GuildImageStyle = "banner2"
	// GuildBanner3 is a large image with guild icon, name and online count. In
	// the footer, Discord logo on the left and "Chat Now" on the right.
	//
	// Example: https://discordapp.com/api/guilds/81384788765712384/widget.png?style=banner3
	GuildBanner3 GuildImageStyle = "banner3"
	// GuildBanner4 is a large Discord logo at the top of the widget.
	// Guild icon, name and online count in the middle portion of the widget
	// and a "JOIN MY SERVER" button at the bottom.
	//
	// Example: https://discordapp.com/api/guilds/81384788765712384/widget.png?style=banner4
	GuildBanner4 GuildImageStyle = "banner4"
)

type Image

type Image struct {
	// ContentType is optional and will be automatically detected. However, it
	// should always return "image/jpeg," "image/png" or "image/gif".
	ContentType string

	// Just raw content of the file.
	Content []byte
}

Image wraps around the Data URI Scheme that Discord uses: https://discordapp.com/developers/docs/reference#image-data

func DecodeImage

func DecodeImage(data []byte) (*Image, error)

func (Image) Encode

func (i Image) Encode() ([]byte, error)

func (Image) MarshalJSON

func (i Image) MarshalJSON() ([]byte, error)

func (*Image) UnmarshalJSON

func (i *Image) UnmarshalJSON(v []byte) error

func (Image) Validate

func (i Image) Validate(maxSize int) error

type LoginResponse added in v0.0.2

type LoginResponse struct {
	MFA    bool   `json:"mfa"`
	SMS    bool   `json:"sms"`
	Ticket string `json:"ticket"`
	Token  string `json:"token"`
}

type ModifyChannelData

type ModifyChannelData struct {
	// Name is the 2-100 character channel name.
	//
	// Channel Types: All
	Name string `json:"name,omitempty"`
	// Type is the type of the channel.
	// Only conversion between text and news is supported and only in guilds
	// with the "NEWS" feature
	//
	// Channel Types: Text, News
	Type *discord.ChannelType `json:"type,omitempty"`
	// Postion is the position of the channel in the left-hand listing
	//
	// Channel Types: All
	Position option.NullableInt `json:"position,omitempty"`
	// Topic is the 0-1024 character channel topic.
	//
	// Channel Types: Text, News
	Topic option.NullableString `json:"topic,omitempty"`
	// NSFW specifies whether the channel is nsfw.
	//
	// Channel Types: Text, News, Store.
	NSFW option.NullableBool `json:"nsfw,omitempty"`
	// UserRateLimit is the amount of seconds a user has to wait before sending
	// another message (0-21600).
	// Bots, as well as users with the permission manage_messages or
	// manage_channel, are unaffected.
	//
	// Channel Types: Text
	UserRateLimit option.NullableUint `json:"rate_limit_per_user,omitempty"`
	// VoiceBitrate is the bitrate (in bits) of the voice channel.
	// 8000 to 96000 (128000 for VIP servers)
	//
	// Channel Types: Voice
	VoiceBitrate option.NullableUint `json:"bitrate,omitempty"`
	// VoiceUserLimit is the user limit of the voice channel.
	// 0 refers to no limit, 1 to 99 refers to a user limit.
	//
	// Channel Types: Voice
	VoiceUserLimit option.NullableUint `json:"user_limit,omitempty"`
	// Permissions are the channel or category-specific permissions.
	//
	// Channel Types: All
	Permissions *[]discord.Overwrite `json:"permission_overwrites,omitempty"`
	// CategoryID is the id of the new parent category for a channel.
	// Channel Types: Text, News, Store, Voice
	CategoryID discord.ChannelID `json:"parent_id,string,omitempty"`
}

https://discord.com/developers/docs/resources/channel#modify-channel-json-params

type ModifyEmojiData added in v0.7.0

type ModifyEmojiData struct {
	// Name is the name of the emoji.
	Name string `json:"name,omitempty"`
	// Roles are the roles to which this emoji will be whitelisted.
	Roles *[]discord.RoleID `json:"roles,omitempty"`
}

https://discord.com/developers/docs/resources/emoji#modify-guild-emoji-json-params

type ModifyGuildData

type ModifyGuildData struct {
	// Name is the guild's name.
	Name string `json:"name,omitempty"`
	// Region is the guild's voice region id.
	Region option.NullableString `json:"region,omitempty"`

	// Verification is the verification level.
	//
	// This field is nullable.
	Verification *discord.Verification `json:"verification_level,omitempty"`
	// Notification is the default message notification level.
	//
	// This field is nullable.
	Notification *discord.Notification `json:"default_message_notifications,omitempty"`
	// ExplicitFilter is the explicit content filter level.
	//
	// This field is nullable.
	ExplicitFilter *discord.ExplicitFilter `json:"explicit_content_filter,omitempty"`

	// AFKChannelID is the id for the afk channel.
	//
	// This field is nullable.
	AFKChannelID discord.ChannelID `json:"afk_channel_id,string,omitempty"`
	// AFKTimeout is the afk timeout in seconds.
	AFKTimeout option.Seconds `json:"afk_timeout,omitempty"`
	// Icon is the base64 1024x1024 png/jpeg/gif image for the guild icon
	// (can be animated gif when the server has the ANIMATED_ICON feature).
	Icon *Image `json:"icon,omitempty"`
	// Splash is the base64 16:9 png/jpeg image for the guild splash
	// (when the server has the INVITE_SPLASH feature).
	Splash *Image `json:"splash,omitempty"`
	// Banner is the base64 16:9 png/jpeg image for the guild banner (when the
	// server has BANNER feature).
	Banner *Image `json:"banner,omitempty"`

	// OwnerID is the user id to transfer guild ownership to (must be owner).
	OwnerID discord.UserID `json:"owner_id,omitempty"`

	// SystemChannelID is the id of the channel where guild notices such as
	// welcome messages and boost events are posted.
	//
	// This field is nullable.
	SystemChannelID discord.ChannelID `json:"system_channel_id,omitempty"`
	// RulesChannelID is the id of the channel where "PUBLIC" guilds display
	// rules and/or guidelines.
	//
	// This field is nullable.
	RulesChannelID discord.ChannelID `json:"rules_channel_id,omitempty"`
	// PublicUpdatesChannelID is the id of the channel where admins and
	// moderators of "PUBLIC" guilds receive notices from Discord.
	//
	// This field is nullable.
	PublicUpdatesChannelID discord.ChannelID `json:"public_updates_channel_id,omitempty"`

	// PreferredLocale is the preferred locale of a "PUBLIC" guild used in
	// server discovery and notices from Discord.
	//
	// This defaults to "en-US".
	PreferredLocale option.NullableString `json:"preferred_locale,omitempty"`
}

https://discordapp.com/developers/docs/resources/guild#modify-guild-json-params

type ModifyGuildWidgetData added in v0.8.2

type ModifyGuildWidgetData struct {
	// Enabled specifies whether the widget is enabled.
	Enabled option.Bool `json:"enabled,omitempty"`
	// ChannelID is the widget channel id.
	ChannelID discord.ChannelID `json:"channel_id,omitempty"`
}

https://discord.com/developers/docs/resources/guild#guild-embed-object-guild-embed-structure

type ModifyIntegrationData added in v0.7.0

type ModifyIntegrationData struct {
	// ExpireBehavior is the behavior when an integration subscription lapses
	// (see the integration expire behaviors documentation).
	ExpireBehavior *discord.ExpireBehavior `json:"expire_behavior,omitempty"`
	// ExpireGracePeriod is the period (in days) where the integration will
	// ignore lapsed subscriptions.
	ExpireGracePeriod option.NullableInt `json:"expire_grace_period,omitempty"`
	// EnableEmoticons specifies whether emoticons should be synced for this
	// integration (twitch only currently).
	EnableEmoticons option.NullableBool `json:"enable_emoticons,omitempty"`
}

https://discord.com/developers/docs/resources/guild#modify-guild-integration-json-params

type ModifyMemberData added in v0.7.0

type ModifyMemberData struct {
	// Nick is the value to set users nickname to.
	//
	// Requires MANAGE_NICKNAMES.
	Nick option.String `json:"nick,omitempty"`
	// Roles is an array of role ids the member is assigned.
	//
	// Requires MANAGE_ROLES.
	Roles *[]discord.RoleID `json:"roles,omitempty"`
	// Mute specifies whether the user is muted in voice channels.
	//
	// Requires MUTE_MEMBERS.
	Mute option.Bool `json:"mute,omitempty"`
	// Deaf specifies whether the user is deafened in voice channels.
	//
	// Requires DEAFEN_MEMBERS.
	Deaf option.Bool `json:"deaf,omitempty"`

	// Voice channel is the id of channel to move user to (if they are
	// connected to voice).
	//
	// Requires MOVE_MEMBER
	VoiceChannel discord.ChannelID `json:"channel_id,omitempty"`
}

https://discord.com/developers/docs/resources/guild#add-guild-member-json-params

type ModifyRoleData added in v0.7.0

type ModifyRoleData struct {
	// Name is the 	name of the role.
	Name option.NullableString `json:"name,omitempty"`
	// Permissions is the bitwise value of the enabled/disabled permissions.
	Permissions *discord.Permissions `json:"permissions,omitempty,string"`
	// Permissions is the bitwise value of the enabled/disabled permissions.
	Color option.NullableColor `json:"color,omitempty"`
	// Hoist specifies whether the role should be displayed separately in the
	// sidebar.
	Hoist option.NullableBool `json:"hoist,omitempty"`
	// Mentionable specifies whether the role should be mentionable.
	Mentionable option.NullableBool `json:"mentionable,omitempty"`
}

https://discord.com/developers/docs/resources/guild#modify-guild-role-json-params

type ModifySelfData

type ModifySelfData struct {
	// Username is the user's username, if changed may cause the user's
	// discriminator to be randomized.
	Username option.String `json:"username,omitempty"`
	// Avatar modifies the user's avatar.
	Avatar *Image `json:"image,omitempty"`
}

https://discord.com/developers/docs/resources/user#modify-current-user-json-params

type ModifyWebhookData

type ModifyWebhookData struct {
	// Name is the default name of the webhook.
	Name option.String `json:"name,omitempty"`
	// Avatar is the image for the default webhook avatar.
	Avatar *Image `json:"avatar,omitempty"`
	// ChannelID is the new channel id this webhook should be moved to.
	ChannelID discord.ChannelID `json:"channel_id,omitempty"`
}

https://discord.com/developers/docs/resources/webhook#modify-webhook-json-params

type MoveChannelData added in v0.6.3

type MoveChannelData struct {
	// ID is the channel id.
	ID discord.ChannelID `json:"id"`
	// Position is the sorting position of the channel
	Position option.Int `json:"position"`
}

type MoveRoleData added in v0.7.0

type MoveRoleData struct {
	// ID is the id of the role.
	ID discord.RoleID `json:"id"`
	// Position is the sorting position of the role.
	Position option.NullableInt `json:"position,omitempty"`
}

https://discord.com/developers/docs/resources/guild#modify-guild-role-positions-json-params

type PruneCountData added in v0.8.6

type PruneCountData struct {
	// Days is the number of days to count prune for (1 or more, default 7).
	Days uint `schema:"days"`
	// IncludedRoles are the role(s) to include.
	IncludedRoles []discord.RoleID `schema:"include_roles,omitempty"`
}

https://discord.com/developers/docs/resources/guild#get-guild-prune-count-query-string-params

type PruneData added in v0.8.6

type PruneData struct {
	// Days is the number of days to prune (1 or more, default 7).
	Days uint `schema:"days"`
	// ReturnCount specifies whether 'pruned' is returned. Discouraged for
	// large guilds.
	ReturnCount bool `schema:"compute_prune_count"`
	// IncludedRoles are the role(s) to include.
	IncludedRoles []discord.RoleID `schema:"include_roles,omitempty"`
}

https://discord.com/developers/docs/resources/guild#begin-guild-prune-query-string-params

type SendMessageData

type SendMessageData struct {
	// Content are the message contents (up to 2000 characters).
	Content string `json:"content,omitempty"`
	// Nonce is a nonce that can be used for optimistic message sending.
	Nonce string `json:"nonce,omitempty"`

	// TTS is true if this is a TTS message.
	TTS bool `json:"tts,omitempty"`
	// Embed is embedded rich content.
	Embed *discord.Embed `json:"embed,omitempty"`

	Files []SendMessageFile `json:"-"`

	// AllowedMentions are the allowed mentions for a message.
	AllowedMentions *AllowedMentions `json:"allowed_mentions,omitempty"`
}

SendMessageData is the full structure to send a new message to Discord with.

func (*SendMessageData) WriteMultipart

func (data *SendMessageData) WriteMultipart(body *multipart.Writer) error

type SendMessageFile

type SendMessageFile struct {
	Name   string
	Reader io.Reader
}

SendMessageFile represents a file to be uploaded to Discord.

type Session added in v0.6.0

type Session struct {
	Limiter *rate.Limiter

	Token     string
	UserAgent string
}

Session keeps a single session. This is typically wrapped around Client.

func (*Session) InjectRequest added in v0.6.0

func (s *Session) InjectRequest(r httpdriver.Request) error

func (*Session) OnResponse added in v0.6.0

func (s *Session) OnResponse(r httpdriver.Request, resp httpdriver.Response) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL