harmony

package module
v0.21.0 Latest Latest
Warning

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

Go to latest
Published: May 22, 2021 License: MIT Imports: 29 Imported by: 0

README

GoDoc License MIT Discord Build Status

Harmony

Harmony is a peaceful Go module for interacting with Discord's API.

Although this package is usable, it still is under active development so please don't use it for anything other than experiments, yet.

Contents

Installation

Make sure you have a working Go installation, if not see this page first.

Then, install this package with the go get command:

go get github.com/skwair/harmony

Note that go get will always pull the latest version from the master branch before Go 1.11. With newer versions and Go modules enabled, the latest minor or patch release will be downloaded. go get github.com/skwair/harmony@major.minor.patch can be used to download a specific version. See Go modules for more information.

Usage

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/skwair/harmony"
)

func main() {
    client, err := harmony.NewClient("your.bot.token")
    if err != nil {
        log.Fatal(err)
    }

    // Get information about the current user (the bot itself).
    u, err := client.User("@me").Get(context.Background())
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println(u)
}

For information about how to create bots and more examples on how to use this package, check out the examples directory and the tests.

Testing

For now, only some end to end tests are provided with this module. To run them, you will need a valid bot token and a valid Discord server ID. The bot attached to the token must be in the server with administrator permissions.

  1. Create a Discord test server

From a Discord client and with you main account, simply create a new server. Then, right click on the new server and get its ID.

Note that for the UI to have the Copy ID option when right clicking on the server, you will need to enable developer mode. You can find this option in User settings > Appearance > Advanced > Developer Mode.

  1. Create a bot and add it to the test Discord server

Create a bot (or use an existing one) and add it to the freshly created server.

See the example directory for information on how to create a bot and add it to a server.

  1. Set required environment variables and run the tests

Set HARMONY_TEST_BOT_TOKEN to the token of your bot and HARMONY_TEST_GUILD_ID to the ID of the server you created and simply run:

⚠️ For the tests to be reproducible, they will start by deleting ALL channels in the provided server. Please make sure to provide a server created ONLY for those tests. ⚠️

go test -v -race ./...

Step 1 and 2 must be done only once for initial setup. Once you have your bot token and the ID of your test server, you can run the tests as many times as you want.

How does it compare to DiscordGo?

Harmony exposes its API differently. It uses a resource-based approach which organizes methods by topic, greatly reducing the number of methods on the main Client type. The goal by doing this is to have a more friendly API which is easier to navigate.

Another key difference is in the "event handler" mechanism. Instead of having a single method that takes an interface{} as a parameter and guesses which event you registered a handler for based on its concrete type, this library provides a dedicated method for each event type, making it clear what signature your handler must have and ensuring it at compile time, not at runtime.

Each action that results in an entry in the audit log has a ...WithReason form, allowing to set a reason for the change (see the X-Audit-Log-Reason header documentation for more information).

Finally, this library has a full support of the context package, allowing the use of timeouts, deadlines and cancellation when interacting with Discord's API.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Original logo by Renee French, dressed with the cool t-shirt by @HlneChd.

Documentation

Overview

Package harmony provides an interface to the Discord API (https://discord.com/developers/docs/intro).

Getting started

The first thing you do with Harmony is to create a Client. NewClient does just that by returning a new Client pre-configured with sain defaults which should work fine in most cases. However, should you need a more specific configuration, you can always tweak it with optional `ClientOption`s. See the documentation of NewClient and the ClientOption type for more information on how to do so.

client, err := harmony.NewClient("your.bot.token")
if err != nil {
	// Handle error
}

Once you have a Client, you can start interacting with the Discord API, but some methods (such as event handlers) won't be available until you connect to Discord's Gateway. You can do so by simply calling the Connect method of the Client:

if err := client.Connect(context.TODO()); err != nil {
	// Handle error
}
defer client.Disconnect() // Gracefully disconnect

It is only when successfully connected to the Gateway that your bot will appear as online and your Client will be able to receive events and send messages.

Using the HTTP API

Harmony's HTTP API is organized by resource. A resource maps to a core concept in the Discord world, such as a User or a Channel. Here is the list of resources you can interact with:

  • Guild
  • Channel
  • User
  • Webhook
  • Invite

Every interaction you can have with a resource can be accessed via methods attached to it. For example, if you wish to send a message to a channel, first access to the desired channel resource, then send the message:

msg, err := client.Channel("channel-id").SendMessage("content of the message")
if err != nil {
	// Handle error
}
// msg is the message sent

Endpoints that do not fall into one of those resource (creating a Guild for example, or getting valid Voice Regions) are directly available on the Client.

Registering event handlers

To receive messages, use the OnMessageCreate method and give it your handler. It will be called each time a message is sent to a channel your bot is in with the message as a parameter.

client.OnMessageCreate(func(msg *discord.Message) {
	fmt.Println(msg.Content)
})

To register handlers for other types of events, see Client.On* methods.

Note that your handlers are called in their own goroutine, meaning whatever you do inside of them won't block future events.

Using the state

When connecting to Discord, a session state is created with initial data sent by Discord's Gateway. As events are received by the client, this state is constantly updated so it always have the newest data available.

This session state acts as a cache to avoid making requests over the HTTP API each time. If you need to get information about the current user, you can simply query the current state like so:

user := client.State.Me()

Because this state might become memory hungry for bots that are in a very large number of servers, you can fine-tune events you want to track with the WithGatewayIntents option. State can also be completely disabled using the WithStateTracking option while creating the harmony client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelPinsUpdate

type ChannelPinsUpdate struct {
	ChannelID        string       `json:"channel_id"`
	LastPinTimestamp discord.Time `json:"last_pin_timestamp"`
}

ChannelPinsUpdate is Fired when a message is pinned or unpinned in a text channel.

type Client

type Client struct {
	State *State
	// contains filtered or unexported fields
}

Client is used to communicate with Discord's API. To start receiving events from the Gateway with a Client, you first need to call its Connect method.

func NewClient

func NewClient(token string, opts ...ClientOption) (*Client, error)

NewClient creates a new client to work with Discord's API. It is meant to be long lived and shared across your application. The token is automatically prefixed with "Bot ", which is a requirement by Discord for bot users. Automated normal user accounts (generally called "self-bots"), are not supported. To customize a Client, refer to available ClientOption.

func (*Client) Application added in v0.21.0

func (c *Client) Application(appID string) *application.Resource

func (*Client) Channel

func (c *Client) Channel(id string) *channel.Resource

Channel returns a new channel resource to manage the channel with the given ID.

func (*Client) Connect

func (c *Client) Connect(ctx context.Context) error

Connect connects and identifies the client to the Discord Gateway.

func (*Client) CreateGuild

func (c *Client) CreateGuild(ctx context.Context, name string) (*discord.Guild, error)

CreateGuild creates a new guild with the given name. Returns the created guild on success. Fires a Guild Create Gateway event.

func (*Client) Disconnect

func (c *Client) Disconnect()

Disconnect closes the connection to the Discord Gateway.

func (*Client) Gateway

func (c *Client) Gateway(ctx context.Context) (string, error)

Gateway returns a valid WSS URL, which the client can use for connecting.

func (*Client) GatewayBot

func (c *Client) GatewayBot(ctx context.Context) (string, int, error)

GatewayBot returns a valid WSS URL and the recommended number of shards to connect with.

func (*Client) GetApplicationInfo

func (c *Client) GetApplicationInfo(ctx context.Context) (*discord.Application, error)

GetApplicationInfo returns the current user's OAuth2 application info.

func (*Client) GetVoiceRegions

func (c *Client) GetVoiceRegions(ctx context.Context) ([]discord.VoiceRegion, error)

GetVoiceRegions returns a list of available voice regions that can be used when creating or updating servers.

func (*Client) Guild

func (c *Client) Guild(id string) *guild.Resource

Guild returns a new guild resource to manage the guild with the given ID.

func (*Client) Interaction

func (c *Client) Interaction(appID, intID, intToken string) *interaction.Resource

Interaction returns a new Interaction resource to manage interactions. Due to the nature of interactions (i.e. tokens expire in 15 minutes, etc), the API differs than that of the other resources.

func (*Client) Invite

func (c *Client) Invite(code string) *invite.Resource

Invite returns a new invite resource to manage the invite with the given code.

func (*Client) JoinVoiceChannel

func (c *Client) JoinVoiceChannel(ctx context.Context, guildID, channelID string, mute, deaf bool) (*voice.Connection, error)

JoinVoiceChannel will create a new voice connection to the given voice channel. If you already have an existing connection and want to switch to a different channel instead, use the SwitchVoiceChannel method. This method is safe to call from multiple goroutines, but connections will happen sequentially. To properly leave the voice channel, call LeaveVoiceChannel.

func (*Client) LeaveVoiceChannel

func (c *Client) LeaveVoiceChannel(ctx context.Context, guildID string) error

LeaveVoiceChannel notifies the Gateway we want the voice channel we are connected to in the given guild.

func (*Client) OnChannelCreate

func (c *Client) OnChannelCreate(f func(c *discord.Channel))

OnChannelCreate registers the handler function for the "CHANNEL_CREATE" event. This event is fired when a new channel is created, relevant to the current user.

func (*Client) OnChannelDelete

func (c *Client) OnChannelDelete(f func(c *discord.Channel))

OnChannelDelete registers the handler function for the "CHANNEL_DELETE" event. This event is fired when a channel is deleted, relevant to the current user.

func (*Client) OnChannelPinsUpdate

func (c *Client) OnChannelPinsUpdate(f func(cpu *ChannelPinsUpdate))

OnChannelPinsUpdate registers the handler function for the "CHANNEL_PINS_UPDATE" event. This event is fired when a message is pinned or unpinned, but not when a pinned message is deleted.

func (*Client) OnChannelUpdate

func (c *Client) OnChannelUpdate(f func(c *discord.Channel))

OnChannelUpdate registers the handler function for the "CHANNEL_UPDATE" event. This event is fired when a channel is updated, relevant to the current user.

func (*Client) OnGuildBanAdd

func (c *Client) OnGuildBanAdd(f func(ban *GuildBan))

OnGuildBanAdd registers the handler function for the "GUILD_BAN_ADD" event.

func (*Client) OnGuildBanRemove

func (c *Client) OnGuildBanRemove(f func(ban *GuildBan))

OnGuildBanRemove registers the handler function for the "GUILD_BAN_REMOVE" event. This event is fired when a guild is updated.

func (*Client) OnGuildCreate

func (c *Client) OnGuildCreate(f func(g *discord.Guild))

OnGuildCreate registers the handler function for the "GUILD_CREATE" event. This event can be sent in three different scenarios:

  1. When a user is initially connecting, to lazily load and backfill information for all unavailable guilds sent in the Ready event.
  2. When a Guild becomes available again to the client.
  3. When the current user joins a new Guild.

func (*Client) OnGuildDelete

func (c *Client) OnGuildDelete(f func(g *discord.UnavailableGuild))

OnGuildDelete registers the handler function for the "GUILD_DELETE" event. This event is fired when a guild becomes unavailable during a guild outage, or when the user leaves or is removed from a guild. If the unavailable field is not set, the user was removed from the guild.

func (*Client) OnGuildEmojisUpdate

func (c *Client) OnGuildEmojisUpdate(f func(emojis *GuildEmojis))

OnGuildEmojisUpdate registers the handler function for the "GUILD_EMOJIS_UPDATE" event. Fired when a guild's emojis have been updated.

func (*Client) OnGuildIntegrationsUpdate

func (c *Client) OnGuildIntegrationsUpdate(f func(u *GuildIntegrationUpdate))

OnGuildIntegrationsUpdate registers the handler function for the "GUILD_INTEGRATIONS_UPDATE" event. Fired when a guild integration is updated.

func (*Client) OnGuildInviteCreate

func (c *Client) OnGuildInviteCreate(f func(i *GuildInviteCreate))

OnGuildInviteCreate registers the handler function for the "GUILD_ROLE_DELETE" event. Fired when a guild role is deleted.

func (*Client) OnGuildInviteDelete

func (c *Client) OnGuildInviteDelete(f func(i *GuildInviteDelete))

OnGuildInviteDelete registers the handler function for the "GUILD_ROLE_DELETE" event. Fired when a guild role is deleted.

func (*Client) OnGuildMemberAdd

func (c *Client) OnGuildMemberAdd(f func(m *GuildMemberAdd))

OnGuildMemberAdd registers the handler function for the "GUILD_MEMBER_ADD" event. Fired when a new user joins a guild.

func (*Client) OnGuildMemberRemove

func (c *Client) OnGuildMemberRemove(f func(m *GuildMemberRemove))

OnGuildMemberRemove registers the handler function for the "GUILD_MEMBER_REMOVE" event. Fired when a user is removed from a guild (leave/kick/ban).

func (*Client) OnGuildMemberUpdate

func (c *Client) OnGuildMemberUpdate(f func(m *GuildMemberUpdate))

OnGuildMemberUpdate registers the handler function for the "GUILD_MEMBER_UPDATE" event. Fired when a guild member is updated.

func (*Client) OnGuildMembersChunk

func (c *Client) OnGuildMembersChunk(f func(m *GuildMembersChunk))

OnGuildMembersChunk registers the handler function for the "GUILD_MEMBERS_CHUNK" event. Sent in response to Guild Request Members.

func (*Client) OnGuildRoleCreate

func (c *Client) OnGuildRoleCreate(f func(r *GuildRole))

OnGuildRoleCreate registers the handler function for the "GUILD_ROLE_CREATE" event. Fired when a guild role is created.

func (*Client) OnGuildRoleDelete

func (c *Client) OnGuildRoleDelete(f func(r *GuildRoleDelete))

OnGuildRoleDelete registers the handler function for the "GUILD_ROLE_DELETE" event. Fired when a guild role is deleted.

func (*Client) OnGuildRoleUpdate

func (c *Client) OnGuildRoleUpdate(f func(r *GuildRole))

OnGuildRoleUpdate registers the handler function for the "GUILD_ROLE_UPDATE" event. Fired when a guild role is updated.

func (*Client) OnGuildUpdate

func (c *Client) OnGuildUpdate(f func(g *discord.Guild))

HandleGuildUpdate registers the handler function for the "GUILD_UPDATE" event.

func (*Client) OnInteractionCreate

func (c *Client) OnInteractionCreate(f func(i *discord.Interaction))

func (*Client) OnMessageAck

func (c *Client) OnMessageAck(f func(ack *MessageAck))

OnMessageAck registers the handler function for the "MESSAGE_ACK" event.

func (*Client) OnMessageCreate

func (c *Client) OnMessageCreate(f func(m *discord.Message))

OnMessageCreate registers the handler function for the "MESSAGE_CREATE" event. Fired when a message is created.

func (*Client) OnMessageDelete

func (c *Client) OnMessageDelete(f func(m *MessageDelete))

OnMessageDelete registers the handler function for the "MESSAGE_DELETE" event. Fired when a message is deleted.

func (*Client) OnMessageDeleteBulk

func (c *Client) OnMessageDeleteBulk(f func(mdb *MessageDeleteBulk))

OnMessageDeleteBulk registers the handler function for the "MESSAGE_DELETE_BULK" event. Fired when multiple messages are deleted at once.

func (*Client) OnMessageReactionAdd

func (c *Client) OnMessageReactionAdd(f func(r *MessageReaction))

OnMessageReactionAdd registers the handler function for the "MESSAGE_REACTION_ADD" event. Fired when a user adds a reaction to a message.

func (*Client) OnMessageReactionRemove

func (c *Client) OnMessageReactionRemove(f func(r *MessageReaction))

OnMessageReactionRemove registers the handler function for the "MESSAGE_REACTION_REMOVE" event. Fired when a user removes a reaction from a message.

func (*Client) OnMessageReactionRemoveAll

func (c *Client) OnMessageReactionRemoveAll(f func(r *MessageReactionRemoveAll))

OnMessageReactionRemoveAll registers the handler function for the "MESSAGE_REACTION_REMOVE_ALL" event. Fired when a user explicitly removes all reactions from a message.

func (*Client) OnMessageReactionRemoveEmoji

func (c *Client) OnMessageReactionRemoveEmoji(f func(r *MessageReactionRemoveEmoji))

HandleMessageReactionRemoveEmoji registers the handler function for the "MESSAGE_REACTION_REMOVE_ALL" event. Fired when a user explicitly removes all reactions from a message.

func (*Client) OnMessageUpdate

func (c *Client) OnMessageUpdate(f func(m *discord.Message))

OnMessageUpdate registers the handler function for the "MESSAGE_UPDATE" event. Fired when a message is updated. Unlike creates, message updates may contain only a subset of the full message object payload (but will always contain an id and channel_id).

func (*Client) OnPresenceUpdate

func (c *Client) OnPresenceUpdate(f func(p *discord.Presence))

OnPresenceUpdate registers the handler function for the "PRESENCE_UPDATE" event. This event is fired when a user's presence is updated for a guild. The user object within this event can be partial, the only field which must be sent is the id field, everything else is optional. Along with this limitation, no fields are required, and the types of the fields are not validated. Your client should expect any combination of fields and types within this event.

func (*Client) OnReady

func (c *Client) OnReady(f func(r *Ready))

OnReady registers the handler function for the "READY" event.

func (*Client) OnTypingStart

func (c *Client) OnTypingStart(f func(ts *TypingStart))

OnTypingStart registers the handler function for the "TYPING_START" event. Fired when a user starts typing in a channel.

func (*Client) OnUserUpdate

func (c *Client) OnUserUpdate(f func(u *discord.User))

OnUserUpdate registers the handler function for the "USER_UPDATE" event. Fired when properties about the user change.

func (*Client) OnVoiceServerUpdate

func (c *Client) OnVoiceServerUpdate(f func(update *voice.ServerUpdate))

OnVoiceServerUpdate registers the handler function for the "VOICE_SERVER_UPDATE" event. Fired when a guild's voice server is updated. This is Fired when initially connecting to voice, and when the current voice instance fails over to a new server.

func (*Client) OnVoiceStateUpdate

func (c *Client) OnVoiceStateUpdate(f func(update *voice.StateUpdate))

OnVoiceStateUpdate registers the handler function for the "VOICE_STATE_UPDATE" event. Fired when someone joins/leaves/moves voice channels.

func (*Client) OnWebhooksUpdate

func (c *Client) OnWebhooksUpdate(f func(wu *WebhooksUpdate))

OnWebhooksUpdate registers the handler function for the "WEBHOOKS_UPDATE" event. Fired when a guild channel's webhook is created, updated, or deleted.

func (*Client) RequestGuildMembers

func (c *Client) RequestGuildMembers(guildID, query string, limit int) error

RequestGuildMembers is used to request offline members for the guild. When initially connecting, the gateway will only send offline members if a guild has less than the large_threshold members (value in the Gateway Identify). If a client wishes to receive additional members, they need to explicitly request them via this operation. The server will send Guild Members Chunk events in response with up to 1000 members per chunk until all members that match the request have been sent. query is a string that username starts with, or an empty string to return all members. limit is the maximum number of members to send or 0 to request all members matched. You need to be connected to the Gateway to call this method, else it will return ErrGatewayNotConnected.

func (*Client) SetBotStatus

func (c *Client) SetBotStatus(status *discord.BotStatus) error

SetBotStatus sets the bot's status. You need to be connected to the Gateway to call this method, else it will return ErrGatewayNotConnected.

func (*Client) SwitchVoiceChannel

func (c *Client) SwitchVoiceChannel(ctx context.Context, guildID string, channelID string) error

SwitchVoiceChannel can be used to switch from a voice channel to another. It requires an active voice connection in the guild. You can get one with JoinVoiceChannel.

func (*Client) User

func (c *Client) User(id string) *user.Resource

User returns a new user resource to manage the user with the given ID. Note that most methods on this resource are only available for the current user (@me).

func (*Client) Webhook

func (c *Client) Webhook(id string) *webhook.Resource

Webhook returns a new webhook resource to manage the webhook with the given ID.

type ClientOption

type ClientOption func(*Client)

ClientOption is a function that configures a Client. It is used in NewClient.

func WithBackoffStrategy

func WithBackoffStrategy(baseDelay, maxDelay time.Duration, factor, jitter float64) ClientOption

WithBackoffStrategy allows you to customize the backoff strategy used when trying to reconnect to the Discord Gateway after an error occurred (such as a network failure). Defaults to 1s (baseDelay), 120s (maxDelay), 1.6 (factor), 0.2 (jitter).

func WithGatewayIntents

func WithGatewayIntents(i discord.GatewayIntent) ClientOption

WithGatewayIntents allows to customize which Gateway Intents the client should subscribe to. See https://discord.com/developers/docs/topics/gateway#gateway-intents for more information. By default, the client subscribes to all unprivileged events.

func WithGuildSubscriptions

func WithGuildSubscriptions(y bool) ClientOption

WithGuildSubscriptions allows to set whether the client should identify to the Gateway with guild subscription enabled or not. Guild subscriptions are guild member presence updates and typing events. Defaults to true. While not deprecated, Guild Subscriptions have been superseded by Gateway Intents. It is recommended to use WithGatewayIntents for better results.

func WithHTTPClient

func WithHTTPClient(client *http.Client) ClientOption

WithHTTPClient can be used to specify the http.Client to use when making HTTP requests to the Discord HTTP API. Defaults to http.DefaultClient.

func WithInitialBotStatus

func WithInitialBotStatus(s *discord.BotStatus) ClientOption

WithInitialBotStatus sets the initial status of the bot that is sent when identifying to the Gateway. It can be later modified with SetBotStatus.

func WithLargeThreshold

func WithLargeThreshold(t int) ClientOption

WithLargeThreshold allows you to set the large threshold when connecting to the Gateway. This threshold will dictate the number of offline guild members are returned with a guild. See: https://discord.com/developers/docs/topics/gateway#request-guild-members for more details. Defaults to 250.

func WithLogger

func WithLogger(l log.Logger) ClientOption

WithLogger can be used to set the logger used by Harmony. Defaults to a standard logger reporting only errors. See the log package for more information about logging with Harmony.

func WithName

func WithName(n string) ClientOption

WithName sets the name of the client. It will be used to set the User-Agent of HTTP requests sent by the Client. Defaults to "Harmony".

func WithSharding

func WithSharding(current, total int) ClientOption

WithSharding allows you to specify a sharding configuration when connecting to the Gateway. See https://discord.com/developers/docs/topics/gateway#sharding for more details. Defaults to nothing, sharding is not enabled.

func WithStateTracking

func WithStateTracking(y bool) ClientOption

WithStateTracking allows you to specify whether the client is tracking the state of the current connection or not. Defaults to true.

type GuildBan

type GuildBan struct {
	*discord.User
	GuildID string `json:"guild_id"`
}

type GuildEmojis

type GuildEmojis struct {
	Emojis  []discord.Emoji `json:"emojis"`
	GuildID string          `json:"guild_id"`
}

type GuildIntegrationUpdate

type GuildIntegrationUpdate struct {
	GuildID string `json:"guild_id"`
}

type GuildInviteCreate

type GuildInviteCreate struct {
	ChannelID      string        `json:"channel_id"`
	Code           string        `json:"code"`
	CreatedAt      discord.Time  `json:"created_at"`
	GuildID        string        `json:"guild_id"`
	Inviter        *discord.User `json:"inviter"`
	MaxAge         int           `json:"max_age"`
	MaxUses        int           `json:"max_uses"`
	TargetUser     *discord.User `json:"target_user"`
	TargetUserType int           `json:"target_user_type"`
	Temporary      bool          `json:"temporary"`
	Uses           int           `json:"uses"`
}

type GuildInviteDelete

type GuildInviteDelete struct {
	ChannelID string `json:"channel_id"`
	GuildID   string `json:"guild_id"`
	Code      string `json:"code"`
}

type GuildMemberAdd

type GuildMemberAdd struct {
	*discord.GuildMember
	GuildID string `json:"guild_id"`
}

type GuildMemberRemove

type GuildMemberRemove struct {
	User    *discord.User `json:"user"`
	GuildID string        `json:"guild_id"`
}

type GuildMemberUpdate

type GuildMemberUpdate struct {
	GuildID string        `json:"guild_id"`
	Roles   []string      `json:"roles"`
	User    *discord.User `json:"user"`
	Nick    string        `json:"nick"`
}

type GuildMembersChunk

type GuildMembersChunk struct {
	GuildID string                `json:"guild_id"`
	Members []discord.GuildMember `json:"members"`
}

type GuildRole

type GuildRole struct {
	GuildID string        `json:"guild_id"`
	Role    *discord.Role `json:"role"`
}

type GuildRoleDelete

type GuildRoleDelete struct {
	GuildID string `json:"guild_id"`
	RoleID  string `json:"role_id"`
}

type MessageAck

type MessageAck struct {
	ChannelID string `json:"channel_id"`
	MessageID string `json:"message_id"`
}

type MessageDelete

type MessageDelete struct {
	ChannelID string `json:"channel_id"`
	MessageID string `json:"id"`
}

type MessageDeleteBulk

type MessageDeleteBulk struct {
	GuildID   string   `json:"guild_id"`
	ChannelID string   `json:"channel_id"`
	IDs       []string `json:"ids"`
}

type MessageReaction

type MessageReaction struct {
	UserID    string         `json:"user_id"`
	GuildID   string         `json:"guild_id"`
	ChannelID string         `json:"channel_id"`
	MessageID string         `json:"message_id"`
	Emoji     *discord.Emoji `json:"emoji"`
}

type MessageReactionRemoveAll

type MessageReactionRemoveAll struct {
	GuildID   string `json:"guild_id"`
	ChannelID string `json:"channel_id"`
	MessageID string `json:"message_id"`
}

type MessageReactionRemoveEmoji

type MessageReactionRemoveEmoji struct {
	GuildID   string         `json:"guild_id"`
	ChannelID string         `json:"channel_id"`
	MessageID string         `json:"message_id"`
	Emoji     *discord.Emoji `json:"emoji"`
}

type Ready

type Ready struct {
	V                    int                        `json:"v"` // Gateway version.
	User                 *discord.User              `json:"user"`
	Guilds               []discord.UnavailableGuild `json:"guilds"`
	SessionID            string                     `json:"session_id"`
	Application          discord.PartialApplication `json:"application"`
	GeoOrderedRTCRegions []string                   `json:"geo_ordered_rtc_regions"`
	Shard                [2]int                     `json:"shard"`
}

Ready is the Event fired by the Gateway after the client sent a valid Identify payload.

type State

type State struct {
	// contains filtered or unexported fields
}

State is a cache of the state of the application that is updated in real-time as events are received from the Gateway. Objects returned by State methods are snapshots of original objects used internally by the State. This means they are safe to be used and modified but they won't be updated as new events are received.

func (*State) Channel

func (s *State) Channel(id string) *discord.Channel

Channel returns a channel given its ID from the state.

func (*State) Channels

func (s *State) Channels() map[string]*discord.Channel

Channels returns a map of channels ID to channels from the state.

func (*State) DM

func (s *State) DM(id string) *discord.Channel

DM returns a DM given its ID from the state.

func (*State) DMs

func (s *State) DMs() map[string]*discord.Channel

DMs returns a map of DM ID to DM from the state.

func (*State) GroupDM

func (s *State) GroupDM(id string) *discord.Channel

GroupDM returns a group DM given its ID from the state.

func (*State) GroupDMs

func (s *State) GroupDMs() map[string]*discord.Channel

GroupDMs returns a map of group DM ID to group DM from the state.

func (*State) Guild

func (s *State) Guild(id string) *discord.Guild

Guild returns a guild given its ID from the state.

func (*State) Guilds

func (s *State) Guilds() map[string]*discord.Guild

Guilds returns a map of guild ID to guild from the state.

func (*State) Me

func (s *State) Me() *discord.User

Me returns the current user from the state.

func (*State) Presence

func (s *State) Presence(userID string) *discord.Presence

Presence returns a presence given a user ID from the state.

func (*State) Presences

func (s *State) Presences() map[string]*discord.Presence

Presences returns a map of user ID to presence from the state.

func (*State) RTT

func (s *State) RTT() time.Duration

RTT returns the Round Trip Time between the client and Discord's Gateway. It is calculated and updated when sending heartbeat payloads (roughly every minute).

func (*State) UnavailableGuild

func (s *State) UnavailableGuild(id string) *discord.UnavailableGuild

UnavailableGuild returns an unavailable guild given its ID from the state.

func (*State) UnavailableGuilds

func (s *State) UnavailableGuilds() map[string]*discord.UnavailableGuild

UnavailableGuilds returns a map of guild ID to unavailable guild from the state.

func (*State) User

func (s *State) User(id string) *discord.User

User returns a user given its ID from the state.

func (*State) Users

func (s *State) Users() map[string]*discord.User

Users returns a map of user ID to user from the state.

type TypingStart

type TypingStart struct {
	ChannelID string `json:"channel_id"`
	GuildID   string `json:"guild_id"`
	UserID    string `json:"user_id"`
	Timestamp int64  `json:"timestamp"`
}

type WebhooksUpdate

type WebhooksUpdate struct {
	GuildID   string `json:"guild_id"`
	ChannelID string `json:"channel_id"`
}

Directories

Path Synopsis
_examples
Package discord contains every Discord resources used throughout Harmony as well as some utility functions and methods to work with them.
Package discord contains every Discord resources used throughout Harmony as well as some utility functions and methods to work with them.
internal
Package log defines an interface that can be implemented in order to provide a logger for Harmony.
Package log defines an interface that can be implemented in order to provide a logger for Harmony.
Package optional defines optional versions of primitive types that can be nil.
Package optional defines optional versions of primitive types that can be nil.
voiceutil
Package voiceutil provides utilities to work with harmony voice connections.
Package voiceutil provides utilities to work with harmony voice connections.

Jump to

Keyboard shortcuts

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