### Full Example: Command Router Setup Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/cmdroute.md A complete example demonstrating how to set up a command router, add command handlers, overwrite commands, and connect to Discord. ```go package main import ( "context" "log" "os" "github.com/diamondburned/arikawa/v3/api" "github.com/diamondburned/arikawa/v3/api/cmdroute" "github.com/diamondburned/arikawa/v3/discord" "github.com/diamondburned/arikawa/v3/gateway" "github.com/diamondburned/arikawa/v3/state" "github.com/diamondburned/arikawa/v3/utils/json/option" ) var commands = []api.CreateCommandData{ { Name: "ping", Description: "Ping the bot", }, { Name: "echo", Description: "Echo a message", Options: []discord.CommandOption{ { Type: discord.StringOption, Name: "message", Description: "Message to echo", Required: true, }, }, }, } func main() { r := cmdroute.NewRouter() r.AddFunc("ping", func(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData { return &api.InteractionResponseData{ Content: option.NewNullableString("Pong!"), } }) r.AddFunc("echo", func(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData { msg, err := data.String("message") if err != nil { return &api.InteractionResponseData{ Content: option.NewNullableString("Error: " + err.Error()), } } return &api.InteractionResponseData{ Content: option.NewNullableString(msg), } }) st := state.New("Bot " + os.Getenv("BOT_TOKEN")) st.AddInteractionHandler(r) st.AddIntents(gateway.IntentGuilds) if err := cmdroute.OverwriteCommands(st, commands); err != nil { log.Fatal(err) } if err := st.Connect(context.Background()); err != nil { log.Fatal(err) } } ``` -------------------------------- ### Basic Bot Example Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/session.md A fundamental example demonstrating how to create a session, set up a message handler, and connect to the gateway. It includes necessary imports and error handling. ```go package main import ( "context" "log" "os" "github.com/diamondburned/arikawa/v3/gateway" "github.com/diamondburned/arikawa/v3/session" ) func main() { token := os.Getenv("BOT_TOKEN") sess := session.NewWithIntents(token, gateway.IntentGuilds, gateway.IntentGuildMessages, ) sess.AddHandler(func(ev *gateway.MessageCreateEvent) { if ev.Author.Bot { return } ctx := context.Background() sess.SendMessage(ctx, ev.ChannelID, "You said: "+ev.Content) }) if err := sess.Connect(context.Background()); err != nil { log.Fatal(err) } } ``` -------------------------------- ### Full Bot Setup with Gateway and Command Routing Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/configuration.md This Go code demonstrates a complete bot setup. It initializes the state with necessary intents, sets up a command router for slash commands, handles message creation events, and registers commands with Discord. Ensure your BOT_TOKEN is set as an environment variable. ```go package main import ( "context" "log" "os" "github.com/diamondburned/arikawa/v3/api" "github.com/diamondburned/arikawa/v3/api/cmdroute" "github.com/diamondburned/arikawa/v3/discord" "github.com/diamondburned/arikawa/v3/gateway" "github.com/diamondburned/arikawa/v3/state" "github.com/diamondburned/arikawa/v3/utils/json/option" ) var commands = []api.CreateCommandData{ {Name: "ping", Description: "Ping!"}, {Name: "echo", Description: "Echo text", Options: []discord.CommandOption{ {Type: discord.StringOption, Name: "text", Description: "Text to echo", Required: true}, }}, } func main() { router := cmdroute.NewRouter() router.AddFunc("ping", func(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData { return &api.InteractionResponseData{ Content: option.NewNullableString("Pong!"), } }) st := state.NewWithIntents( "Bot "+os.Getenv("BOT_TOKEN"), gateway.IntentGuilds, gateway.IntentGuildMessages, ) st.StateLog = func(err error) { if err != nil { log.Println("State:", err) } } st.AddInteractionHandler(router) st.AddHandler(func(ev *gateway.MessageCreateEvent) { if ev.Author.Bot { return } log.Printf("[%s] %s: %s", ev.GuildID, ev.Author, ev.Content) }) if err := cmdroute.OverwriteCommands(st, commands); err != nil { log.Fatal(err) } if err := st.Connect(context.Background()); err != nil { log.Fatal(err) } } ``` -------------------------------- ### Example Middleware: Require Admin Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/cmdroute.md An example middleware function that checks if a user has administrative privileges before proceeding. ```go func requireAdmin(next cmdroute.CommandHandler) cmdroute.CommandHandler { return cmdroute.CommandHandlerFunc(func(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData { // Check if user is admin if !isAdmin(data.Member) { return &api.InteractionResponseData{ Content: option.NewNullableString("You don't have permission"), Flags: api.EphemeralResponse, } } return next.Handle(ctx, data) }) } ``` -------------------------------- ### Basic Command Router Setup Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/configuration.md Creates a new command router and adds a simple command handler for 'ping'. ```go router := cmdroute.NewRouter() router.AddFunc("ping", handlePing) ``` -------------------------------- ### Example: Overwriting Commands Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/cmdroute.md Demonstrates how to define and overwrite application commands using the OverwriteCommands function. ```go commands := []api.CreateCommandData{ { Name: "ping", Description: "Ping the bot", }, { Name: "echo", Description: "Echo a message", Options: []discord.CommandOption{ { Type: discord.StringOption, Name: "message", Description: "Message to echo", Required: true, }, }, }, } if err := cmdroute.OverwriteCommands(client, commands); err != nil { log.Fatal(err) } ``` -------------------------------- ### Get Command Options Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/cmdroute.md Retrieves the command options from CommandData. ```go func (d CommandData) Options() []discord.CommandInteractionOption ``` -------------------------------- ### Full Example: Initialize State and Handle Events Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/state.md Demonstrates initializing the state with specific intents, setting up both PreHandler and Handler for message events, and connecting to Discord. The PreHandler captures deleted messages, while the Handler logs new messages with guild information. ```go package main import ( "context" "log" "os" "github.com/diamondburned/arikawa/v3/gateway" "github.com/diamondburned/arikawa/v3/state" ) func main() { token := os.Getenv("BOT_TOKEN") st := state.NewWithIntents(token, gateway.IntentGuilds, gateway.IntentGuildMessages, gateway.IntentMessageContent, ) st.PreHandler.AddHandler(func(ev *gateway.MessageDeleteEvent) { // Capture message before cache is updated ctx := context.Background() msg, err := st.Message(ev.ChannelID, ev.ID) if err == nil { log.Printf("Deleted message: %s", msg.Content) } }) st.Handler.AddHandler(func(ev *gateway.MessageCreateEvent) { // Cache is already updated guild, _ := st.Guild(ev.GuildID) log.Printf("[%s] %s: %s", guild.Name, ev.Author, ev.Content) }) if err := st.Connect(context.Background()); err != nil { log.Fatal(err) } } ``` -------------------------------- ### Bare Minimum Bot with Ping Command Source: https://github.com/diamondburned/arikawa/blob/v3/README.md This example demonstrates the least amount of code required to create a bot that responds to a '/ping' command. It sets up a state, registers an interaction handler, and overwrites global commands. Ensure the BOT_TOKEN environment variable is set. ```go package main import ( "context" "log" "os" "github.com/diamondburned/arikawa/v3/api" "github.com/diamondburned/arikawa/v3/api/cmdroute" "github.com/diamondburned/arikawa/v3/gateway" "github.com/diamondburned/arikawa/v3/state" "github.com/diamondburned/arikawa/v3/utils/json/option" ) var commands = []api.CreateCommandData{{Name: "ping", Description: "Ping!"}} func main() { r := cmdroute.NewRouter() r.AddFunc("ping", func(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData { return &api.InteractionResponseData{Content: option.NewNullableString("Pong!")} }) s := state.New("Bot " + os.Getenv("BOT_TOKEN")) s.AddInteractionHandler(r) s.AddIntents(gateway.IntentGuilds) if err := cmdroute.OverwriteCommands(s, commands); err != nil { log.Fatalln("cannot update commands:", err) } if err := s.Connect(context.TODO()); err != nil { log.Println("cannot connect:", err) } } ``` -------------------------------- ### Get Gateway Options Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/gateway.md Returns a copy of the gateway's current operational options. ```go func (g *Gateway) Opts() *ws.GatewayOpts ``` -------------------------------- ### Configure Gateway Intents Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/configuration.md Example of creating a new gateway state with specified intents. Privileged intents must be enabled in the Discord Developer Portal and explicitly requested in the code. ```go state := state.NewWithIntents(token, gateway.IntentGuilds, gateway.IntentGuildMembers, // Requires developer portal gateway.IntentGuildPresences, // Requires developer portal gateway.IntentMessageContent, // Requires developer portal ) ``` -------------------------------- ### Get Session Gateway Options Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/session.md Returns a copy of the gateway options used by the session. If the gateway has not been created, it returns default options. ```go func (s *Session) GatewayOpts() *ws.GatewayOpts ``` -------------------------------- ### BotURL Method Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Fetches the gateway URL along with essential metadata such as shard information and session start limits. Returns BotData or an error. ```go func (c *Client) BotURL(ctx context.Context) (*BotData, error) ``` -------------------------------- ### Get Speaking Flags from Connection Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/voice.md Fetches the current speaking flags for the voice connection. ```go flags := conn.SpeakingFlags() ``` -------------------------------- ### Handling API NotFound Error Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/errors.md Shows how to handle a NotFound (404) API error, for example, when a channel might have been deleted. ```go ch, err := client.Channel(ctx, channelID) if err != nil { // Could be 404 if channel was deleted log.Printf("Channel not found: %v", err) } ``` -------------------------------- ### Create Custom Session from Components Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/configuration.md Constructs a fully customized session by providing custom gateway, API client, and handler components. This offers maximum flexibility in session setup. ```go client := api.NewClient(token) handler := handler.New() gateway := // custom gateway setup sess := session.NewCustom( gateway.DefaultIdentifier(token), client, handler, ) ``` -------------------------------- ### Permissions String Method Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/discord-models.md Provides a method to get a string representation of the Permissions value. ```go func (p Permissions) String() string ``` -------------------------------- ### Handle Request Timeouts with Context Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/errors.md Use `context.WithTimeout` to set a deadline for requests. This example demonstrates how to detect and log a `context.DeadlineExceeded` error. ```go ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) deferr cancel() msg, err := client.WithContext(ctx).SendMessage(ctx, channelID, "Hello") if err == context.DeadlineExceeded { log.Println("Request timed out") } ``` -------------------------------- ### Registering Commands with Options Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/configuration.md Defines and registers application commands, including nested subcommand groups and options. This example shows how to structure complex command data for Discord. ```go commands := []api.CreateCommandData{ { Name: "ping", Description: "Ping the bot", }, { Name: "config", Description: "Configuration commands", Options: []discord.CommandOption{ { Type: discord.SubcommandGroupOption, Name: "database", Description: "Database config", Options: []discord.CommandOption{ { Type: discord.SubcommandOption, Name: "set", Description: "Set database config", }, }, }, }, }, } if err := cmdroute.OverwriteCommands(client, commands); err != nil { log.Fatal(err) } ``` -------------------------------- ### Channel Method Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Fetches a specific channel by its Channel ID. Use this to get details about a particular channel. ```go func (c *Client) Channel(ctx context.Context, channelID discord.ChannelID) (*discord.Channel, error) ``` -------------------------------- ### BotURL Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Gets the gateway URL along with metadata (shards, session start limit). ```APIDOC ## BotURL ### Description Gets the gateway URL along with metadata (shards, session start limit). ### Method `func (c *Client) BotURL(ctx context.Context) (*BotData, error)` ### Parameters #### Path Parameters - **ctx** (context.Context) - Required - Context for operations ### Returns - `(*BotData, error)` - Bot gateway data or error ``` -------------------------------- ### Get Bot Gateway URL Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/gateway.md Retrieves the gateway URL along with bot metadata, including shard information and session start limits. ```go func BotURL(ctx context.Context, token string) (*api.BotData, error) ``` -------------------------------- ### Discord Button Component Example Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/message-send.md Creates an action row with different types of buttons (Primary, Secondary, Link) for interactive messages. Requires 'discord.ActionRow' and 'discord.Button'. ```go row := discord.ActionRow{ Components: []discord.Component{ discord.Button{ Label: "Primary", Style: discord.PrimaryButton, CustomID: "primary_btn", }, discord.Button{ Label: "Secondary", Style: discord.SecondaryButton, CustomID: "secondary_btn", }, discord.Button{ Label: "Link", Style: discord.LinkButton, URL: "https://discord.com", }, }, } msg, err := client.SendMessageComplex(ctx, channelID, SendMessageData{ Content: "Choose an option:", Components: []discord.Component{row}, }) ``` -------------------------------- ### Event Handling with Multiple Handlers Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/utils.md Shows how to set up an event handler and register multiple functions to process different event types, including a catch-all for any event. ```go package main import ( "log" "github.com/diamondburned/arikawa/v3/gateway" "github.com/diamondburned/arikawa/v3/utils/handler" ) func main() { h := handler.New() // Add multiple handlers h.AddHandler(func(ev *gateway.ReadyEvent) { log.Println("Bot ready") }) h.AddHandler(func(ev *gateway.MessageCreateEvent) { log.Printf("Message: %s", ev.Content) }) h.AddHandler(func(ev interface{}) { log.Printf("Any event: %T", ev) }) // Dispatch events h.Call(&gateway.ReadyEvent{}) h.Call(&gateway.MessageCreateEvent{ Message: &discord.Message{Content: "Hello"}, }) } ``` -------------------------------- ### Channel Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Gets a channel by ID. ```APIDOC ## Channel ### Description Gets a channel by ID. ### Method `func (c *Client) Channel(ctx context.Context, channelID discord.ChannelID) (*discord.Channel, error)` ### Parameters #### Path Parameters - **ctx** (context.Context) - Required - Context for operations - **channelID** (discord.ChannelID) - Required - Channel ID ### Returns - `(*discord.Channel, error)` - Channel or error ``` -------------------------------- ### Channels Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Gets all channels in a guild. ```APIDOC ## Channels ### Description Gets all channels in a guild. ### Method `func (c *Client) Channels(ctx context.Context, guildID discord.GuildID) ([]discord.Channel, error)` ### Parameters #### Path Parameters - **ctx** (context.Context) - Required - Context for operations - **guildID** (discord.GuildID) - Required - Guild ID ### Returns - `([]discord.Channel, error)` - Channel list or error ``` -------------------------------- ### Create a Simple Discord Bot with Slash Commands Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/README.md This Go program demonstrates how to create a basic Discord bot using the arikawa library. It sets up a command router for slash commands, registers a 'ping' command, and connects to Discord using a bot token. Ensure the BOT_TOKEN environment variable is set. ```go package main import ( "context" "log" "os" "github.com/diamondburned/arikawa/v3/api" "github.com/diamondburned/arikawa/v3/api/cmdroute" "github.com/diamondburned/arikawa/v3/discord" "github.com/diamondburned/arikawa/v3/gateway" "github.com/diamondburned/arikawa/v3/state" "github.com/diamondburned/arikawa/v3/utils/json/option" ) var commands = []api.CreateCommandData{ {Name: "ping", Description: "Ping!"}, } func main() { router := cmdroute.NewRouter() router.AddFunc("ping", func(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData { return &api.InteractionResponseData{ Content: option.NewNullableString("Pong!"), } }) st := state.NewWithIntents("Bot "+os.Getenv("BOT_TOKEN"), gateway.IntentGuilds, ) st.AddInteractionHandler(router) if err := cmdroute.OverwriteCommands(st, commands); err != nil { log.Fatal(err) } if err := st.Connect(context.Background()); err != nil { log.Fatal(err) } } ``` -------------------------------- ### User Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Gets a user by ID. ```APIDOC ## User ### Description Gets a user by ID. ### Method `func (c *Client) User(ctx context.Context, userID discord.UserID) (*discord.User, error)` ### Parameters #### Path Parameters - **ctx** (context.Context) - Required - Context for operations - **userID** (discord.UserID) - Required - User ID to fetch ### Returns - `(*discord.User, error)` - User object or error ``` -------------------------------- ### Me Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Gets the current user object. ```APIDOC ## Me ### Description Gets the current user object. ### Method `func (c *Client) Me(ctx context.Context) (*discord.User, error)` ### Parameters #### Path Parameters - **ctx** (context.Context) - Required - Context for operations ### Returns - `(*discord.User, error)` - Current user or error ``` -------------------------------- ### Initialize State with Intents and Cache Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/README.md Create a new state instance, specify desired intents, and leverage automatic caching for guilds, channels, and messages. ```go state := state.New(token) state.AddIntents(gateway.IntentGuildMessages) // Automatic caching guild, _ := state.Guild(guildID) // Cached channel, _ := state.Channel(channelID) // Cached messages, _ := state.Messages(channelID, 100) // Cached ``` -------------------------------- ### GatewayURL Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Gets the WebSocket gateway URL. ```APIDOC ## GatewayURL ### Description Gets the WebSocket gateway URL. ### Method `func (c *Client) GatewayURL(ctx context.Context) (string, error)` ### Parameters #### Path Parameters - **ctx** (context.Context) - Required - Context for operations ### Returns - `(string, error)` - Gateway URL or error ``` -------------------------------- ### Command Router with Middleware and Groups Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/configuration.md Demonstrates setting up a command router with global and group-specific middleware, as well as nested subcommands. This allows for organized command handling and access control. ```go router := cmdroute.NewRouter() // Global middleware router.Use(logMiddleware, requireGuildMiddleware) // Group middleware router.Group(func(r *Router) { r.Use(requireAdminMiddleware) r.AddFunc("ban", handleBan) r.AddFunc("kick", handleKick) }) // Subcommands router.Sub("config", func(r *Router) { r.AddFunc("set", handleConfigSet) r.AddFunc("get", handleConfigGet) }) ``` -------------------------------- ### Get Gateway URL Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/gateway.md Retrieves the gateway URL from Discord. ```go func URL(ctx context.Context) (string, error) ``` -------------------------------- ### Create New Session Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/session.md Use New to create a session with default settings. Remember to close the session when done. ```go session := session.New("Bot YOUR_TOKEN") deferr session.Close() ``` -------------------------------- ### Basic Voice Configuration Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/configuration.md Sets up a basic voice session by creating a new state and adding the necessary voice intent. A valid session is required to establish voice connections. ```go session := state.New("Bot YOUR_TOKEN") session.AddIntents(gateway.IntentGuildVoiceStates) voiceConn, err := voice.NewSession(session) ``` -------------------------------- ### Get Webhook by ID Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Retrieves a webhook using its unique ID. ```go func (c *Client) Webhook(ctx context.Context, webhookID discord.WebhookID) (*discord.Webhook, error) ``` -------------------------------- ### Get Guild Roles Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Retrieves all roles associated with a specific guild. ```go func (c *Client) Roles(ctx context.Context, guildID discord.GuildID) ([]discord.Role, error) ``` -------------------------------- ### Create Basic Session Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/configuration.md Initializes a new session with default configurations. This is suitable for bots that do not require specific event intents or custom handlers. ```go sess := session.New("Bot YOUR_TOKEN") ``` -------------------------------- ### Get Attachment Argument Value Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/cmdroute.md Retrieves an attachment argument by its name. ```go func (d CommandData) Attachment(name string) (*discord.Attachment, error) ``` -------------------------------- ### Create API Client Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/configuration.md Creates a new API client with default settings. Use this for basic API interactions. ```go client := api.NewClient("Bot YOUR_TOKEN_HERE") ``` -------------------------------- ### Create HTTP Client with Context Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/utils.md Returns a copy of the HTTP client configured with a specific context. This allows for request-scoped settings like timeouts or cancellation. ```go ctxClient := client.WithContext(ctx) ``` -------------------------------- ### Get Role Argument Value Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/cmdroute.md Retrieves a role argument by its name. ```go func (d CommandData) Role(name string) (*discord.Role, error) ``` -------------------------------- ### Get Channel Argument Value Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/cmdroute.md Retrieves a channel argument by its name. ```go func (d CommandData) Channel(name string) (*discord.Channel, error) ``` -------------------------------- ### Run Integration Tests Source: https://github.com/diamondburned/arikawa/blob/v3/README.md Set the BOT_TOKEN environment variable and execute the integration tests using 'go test'. Ensure the BOT_TOKEN is replaced with your actual token. ```sh export BOT_TOKEN="" go test -tags integration -race ./... ``` -------------------------------- ### Custom HTTP Client with Timeout and Middleware Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/utils.md Demonstrates creating a custom HTTP client with a timeout and adding request/response middleware for custom headers and logging. ```go package main import ( "context" "log" "net/http" "time" "github.com/diamondburned/arikawa/v3/api" "github.com/diamondburned/arikawa/v3/utils/httputil" ) func main() { // Create custom HTTP client with timeout httpClient := httputil.NewClient() // Add request middleware httpClient.OnRequest = append(httpClient.OnRequest, func(r httpdriver.Request) error { r.AddHeader(http.Header{ "Custom-Header": []string{"value"}, }) return nil }) // Add response middleware httpClient.OnResponse = append(httpClient.OnResponse, func(r httpdriver.Request, resp httpdriver.Response) error { log.Printf("Response status: %d", resp.GetStatusCode()) return nil }) // Create API client with custom HTTP client client := api.NewCustomClient("Bot YOUR_TOKEN", httpClient) // Use with context timeout ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) defer cancel() user, err := client.WithContext(ctx).Me(ctx) if err != nil { log.Fatal(err) } log.Printf("User: %s#%s", user.Username, user.Discriminator) } ``` -------------------------------- ### Get User Argument Value Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/cmdroute.md Retrieves a user argument by its name. ```go func (d CommandData) User(name string) (*discord.User, error) ``` -------------------------------- ### New Gateway Constructor Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/gateway.md Creates a new Gateway instance with default settings for connecting to the official Discord server. Ensure to defer closing the gateway. ```go gw, err := gateway.New(ctx, "Bot YOUR_TOKEN") if err != nil { log.Fatal(err) } defgw.Close() ``` -------------------------------- ### Get Boolean Argument Value Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/cmdroute.md Retrieves the value of a boolean argument by its name. ```go func (d CommandData) Bool(name string) (bool, error) ``` -------------------------------- ### Create Basic Gateway Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/configuration.md Initializes a new gateway connection with default settings, connecting to the default Discord server without specifying intents. A context is required for managing the connection lifecycle. ```go gw, err := gateway.New(ctx, "Bot YOUR_TOKEN") ``` -------------------------------- ### Gateway Connect Method Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/utils.md Connects to the gateway and yields operations. Requires a context and a handler. ```go func (g *Gateway) Connect(ctx context.Context, handler Handler) <-chan Op ``` -------------------------------- ### Get Float Argument Value Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/cmdroute.md Retrieves the value of a float argument by its name. ```go func (d CommandData) Float(name string) (float64, error) ``` -------------------------------- ### Get Integer Argument Value Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/cmdroute.md Retrieves the value of an integer argument by its name. ```go func (d CommandData) Int(name string) (int64, error) ``` -------------------------------- ### Handle Slash Commands with Router Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/README.md Set up a command router to handle slash commands and their arguments. ```go router := cmdroute.NewRouter() router.AddFunc("mycommand", func(ctx context.Context, data cmdroute.CommandData) *api.InteractionResponseData { arg, _ := data.String("myarg") return &api.InteractionResponseData{ Content: option.NewNullableString("You said: " + arg), } }) ``` -------------------------------- ### Get String Argument Value Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/cmdroute.md Retrieves the value of a string argument by its name. ```go func (d CommandData) String(name string) (string, error) ``` -------------------------------- ### NewClient Constructor Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Creates a new API client with a given token and default HTTP client. Use this for basic client initialization. ```go func NewClient(token string) *Client ``` ```go client := api.NewClient("Bot YOUR_TOKEN_HERE") ``` -------------------------------- ### Get Command Argument by Name Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/cmdroute.md Retrieves a specific command argument by its name. ```go func (d CommandData) Arg(name string) *discord.CommandInteractionOption ``` -------------------------------- ### Create New HTTP Client Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/utils.md Creates a new HTTP client instance. This client can be configured with middleware for request and response handling. ```go client := httputil.NewClient() ``` -------------------------------- ### Initialize State with NoopStore Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/state.md Creates a new state instance using a NoopStore, which performs no operations and always returns errors. This is useful when only API calls are desired without any caching. ```go st := state.NewWithStore(token, store.NoopStore{}) ``` -------------------------------- ### Create Basic State Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/configuration.md Initializes a new state manager with default configurations, including an in-memory store. This is suitable for simple bots or testing purposes. ```go state := state.New("Bot YOUR_TOKEN") ``` -------------------------------- ### Create State with Custom Store Backend Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/configuration.md Initializes a state manager using a custom store backend, such as Redis or a database. This is for implementing custom caching strategies. ```go customStore := store.NewMyRedisStore() // custom implementation state := state.NewWithStore("Bot YOUR_TOKEN", customStore) ``` -------------------------------- ### Get Channel ID from Connection Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/voice.md Retrieves the voice channel ID of the current connection. ```go channelID := conn.ChannelID() ``` -------------------------------- ### Create Session with Intents Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/session.md Use NewWithIntents to create a session and specify gateway intents. This is useful for controlling which events your bot receives. ```go sess := session.NewWithIntents(token, gateway.IntentGuilds, gateway.IntentGuildMessages, ) ``` -------------------------------- ### Create HTTP Client Copy Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/utils.md Returns a shallow copy of the existing HTTP client. This is useful for creating variations of a client without modifying the original. ```go copyClient := client.Copy() ``` -------------------------------- ### Get Guild Member Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Retrieves a specific member from a guild using their guild and user IDs. ```go func (c *Client) Member(ctx context.Context, guildID discord.GuildID, userID discord.UserID) (*discord.Member, error) ``` -------------------------------- ### Create New Router Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/cmdroute.md Instantiates a new, empty router for handling Discord slash commands and interactions. Use this to begin setting up your command structure. ```go router := cmdroute.NewRouter() ``` -------------------------------- ### Get All User's Guilds Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Retrieves a list of all guilds that the user is a member of, without any limit. ```go func (c *Client) AllGuilds(ctx context.Context) ([]discord.Guild, error) ``` -------------------------------- ### Get a Message by ID Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Retrieves a specific message from a channel using its unique message ID. ```go func (c *Client) Message(ctx context.Context, channelID discord.ChannelID, messageID discord.MessageID) (*discord.Message, error) ``` -------------------------------- ### New Gateway Constructor Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/gateway.md Creates a new Gateway instance with default settings for connecting to Discord's official gateway server. ```APIDOC ## func New(ctx context.Context, token string) (*Gateway, error) ### Description Creates a new Gateway with default settings to the official Discord server. ### Parameters #### Path Parameters - **ctx** (context.Context) - Required - Context for gateway setup - **token** (string) - Required - Discord bot token ### Returns - `(*Gateway, error)` - Gateway or error if setup fails ### Example ```go gw, err := gateway.New(ctx, "Bot YOUR_TOKEN") if err != nil { log.Fatal(err) } defer gw.Close() ``` ``` -------------------------------- ### Get Voice State Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/state.md Retrieves a voice state from the cache using the guild and user IDs. ```go func (s *State) VoiceState(guildID discord.GuildID, userID discord.UserID) (*discord.VoiceState, error) ``` -------------------------------- ### Get Gateway Error Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/session.md Retrieves the error associated with the gateway if it has become disconnected and is not attempting to reconnect. ```go func (s *Session) GatewayError() error ``` -------------------------------- ### Get Session Gateway Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/session.md Retrieves the session's gateway instance. This will be nil if the gateway has not been opened. ```go func (s *Session) Gateway() *gateway.Gateway ``` -------------------------------- ### Get Guild ID from Connection Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/voice.md Retrieves the guild ID associated with the current voice connection. ```go guildID := conn.GuildID() ``` -------------------------------- ### Get a Guild by ID Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Retrieves detailed information about a specific guild using its unique guild ID. ```go func (c *Client) Guild(ctx context.Context, guildID discord.GuildID) (*discord.Guild, error) ``` -------------------------------- ### NewCustomClient Constructor Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Creates a new API client with a specified token and a custom HTTP client. Useful for advanced configurations. ```go func NewCustomClient(token string, httpClient *httputil.Client) *Client ``` -------------------------------- ### Connect Session Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/session.md Use Connect to open the gateway and manage the connection. It automatically retries on non-fatal errors and handles session resumption. ```go ctx := context.Background() if err := sess.Connect(ctx); err != nil { log.Fatal(err) } ``` -------------------------------- ### Get All Cached Emojis Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/state.md Retrieves a list of all emojis for a guild that are currently in the cache. This method does not interact with the API. ```go func (s *State) Emojis(guildID discord.GuildID) ([]discord.Emoji, error) ``` -------------------------------- ### Router.Use Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/cmdroute.md Adds middleware to the router. Applies to all subcommands and subrouters. Parent middlewares are applied first. ```APIDOC ## Router.Use ### Description Adds middleware to the router. Applies to all subcommands and subrouters. Parent middlewares are applied first. ### Parameters #### Path Parameters - **mws** (...Middleware) - Required - Middleware functions ### Example ```go router.Use(requireGuild, requirePermissions) ``` ``` -------------------------------- ### Get Multiple Messages Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Fetches a specified number of recent messages from a channel. The limit is capped at 100 messages. ```go func (c *Client) Messages(ctx context.Context, channelID discord.ChannelID, limit uint) ([]discord.Message, error) ``` -------------------------------- ### Get All Channels in a Guild Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/state.md Retrieves a list of all channels within a specified guild, checking the cache first and then the API. ```go func (s *State) Channels(guildID discord.GuildID) ([]discord.Channel, error) ``` -------------------------------- ### Create New State with Custom Store Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/state.md Initializes a new state with a provided custom store backend. This allows for using different caching strategies or persistence mechanisms. ```go func NewWithStore(token string, cabinet *store.Cabinet) *State ``` -------------------------------- ### Get All Cached Guilds Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/state.md Retrieves a list of all guilds currently stored in the cache. This method does not perform an API call. ```go func (s *State) Guilds() ([]discord.Guild, error) ``` -------------------------------- ### Create Session with Intents Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/configuration.md Creates a session and specifies the gateway intents to receive specific events. This is crucial for bots that need to process certain types of events like guilds or messages. ```go sess := session.NewWithIntents("Bot YOUR_TOKEN", gateway.IntentGuilds, gateway.IntentGuildMessages, gateway.IntentMessageContent, ) ``` -------------------------------- ### Create State with Intents Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/configuration.md Initializes a state manager and specifies the gateway intents to enable. This allows the state to receive and process specific types of events. ```go state := state.NewWithIntents("Bot YOUR_TOKEN", gateway.IntentGuilds, gateway.IntentGuildMessages, gateway.IntentGuildMembers, ) ``` -------------------------------- ### Create a Guild Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Initiates the creation of a new Discord guild. Requires specific guild creation data. ```go func (c *Client) CreateGuild(ctx context.Context, data CreateGuildData) (*discord.Guild, error) ``` -------------------------------- ### Get User's Guilds (Limited) Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Fetches a list of guilds the user is currently a member of, up to a maximum of 100 guilds. ```go func (c *Client) Guilds(ctx context.Context, limit uint) ([]discord.Guild, error) ``` -------------------------------- ### New Session Constructors Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/session.md Provides several constructors for creating a new Session instance with different configurations, including default settings, specified gateway intents, custom identifiers, custom components, or from an unopened gateway. ```APIDOC ## func New(token string) *Session Creates a new session with default settings. ### Parameters - **token** (string) - Discord bot or user token ### Returns - `*Session` - New session ### Example ```go session := session.New("Bot YOUR_TOKEN") defer session.Close() ``` --- ## func NewWithIntents(token string, intents ...gateway.Intents) *Session Creates a new session with specified gateway intents. ### Parameters - **token** (string) - Discord token - **intents** (...gateway.Intents) - Gateway intents to enable ### Returns - `*Session` - New session ### Example ```go sess := session.NewWithIntents(token, gateway.IntentGuilds, gateway.IntentGuildMessages, ) ``` --- ## func NewWithIdentifier(id gateway.Identifier) *Session Creates a session with a custom identifier. --- ## func NewCustom(id gateway.Identifier, cl *api.Client, h *handler.Handler) *Session Creates a session from custom components. --- ## func NewWithGateway(g *gateway.Gateway, h *handler.Handler) *Session Constructs a session from an unopened gateway. --- ## func Login(ctx context.Context, email, password, mfa string) (*Session, error) Logs in as a user account. MFA is optional but required if 2FA is enabled. ### Parameters - **email** (string) - Account email - **password** (string) - Account password - **mfa** (string) - 2FA code (empty if not required) ### Returns - `(*Session, error)` - Session or error ### Errors: - `ErrMFA` - Account requires 2FA code - Other errors from login API call ``` -------------------------------- ### User Method Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Fetches a specific user's profile by their User ID. Use this to get information about any Discord user. ```go func (c *Client) User(ctx context.Context, userID discord.UserID) (*discord.User, error) ``` -------------------------------- ### Get Emojis by Guild Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/state.md Retrieves a list of all emojis within a specific guild that are present in the cache. This method does not query the API. ```APIDOC ## func (s *State) Emojis(guildID discord.GuildID) ([]discord.Emoji, error) ### Description Gets all emojis in a guild from cache. ### Parameters - **guildID** (discord.GuildID) - Required - The ID of the guild whose emojis to retrieve ### Returns - **([]discord.Emoji, error)** - A slice of emoji objects or an error if retrieval fails ``` -------------------------------- ### Send Message with Select Menu Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/message-send.md Demonstrates how to create and send a message containing a Discord select menu for role selection. Ensure the CustomID is unique and handled by your application. ```go row := discord.ActionRow{ Components: []discord.Component{ discord.SelectMenu{ CustomID: "role_select", Placeholder: "Select a role", Options: []discord.SelectMenuOption{ { Label: "Role 1", Value: "role_1", }, { Label: "Role 2", Value: "role_2", }, }, }, }, } msg, err := client.SendMessageComplex(ctx, channelID, SendMessageData{ Content: "Choose a role:", Components: []discord.Component{row}, }) ``` -------------------------------- ### User Model Methods Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/discord-models.md Provides utility methods for the User model, such as generating a string representation (Username#Discriminator), a mention string (<@ID>), and a CDN avatar URL. ```go func (u *User) String() string // Username#Discriminator func (u *User) Mention() string // <@ID> func (u *User) AvatarURL() string // CDN avatar URL ``` -------------------------------- ### Get Roles by Guild Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/state.md Retrieves a list of all roles within a specific guild that are present in the cache. This method does not query the API. ```APIDOC ## func (s *State) Roles(guildID discord.GuildID) ([]discord.Role, error) ### Description Gets all roles in a guild from cache. ### Parameters - **guildID** (discord.GuildID) - Required - The ID of the guild whose roles to retrieve ### Returns - **([]discord.Role, error)** - A slice of role objects or an error if retrieval fails ``` -------------------------------- ### Get Guilds Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/state.md Retrieves a list of all guilds currently cached by the state. This method only returns guilds that are present in the local cache. ```APIDOC ## func (s *State) Guilds() ([]discord.Guild, error) ### Description Gets all cached guilds. ### Returns - **([]discord.Guild, error)** - A slice of guild objects or an error if retrieval fails ``` -------------------------------- ### Configure State Event Handlers Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/configuration.md Sets up event handlers for state updates, allowing custom logic to be executed before (PreHandler) or after (Handler) the state cache is updated. ```go // Before cache is updated state.PreHandler.AddHandler(func(ev *gateway.MessageDeleteEvent) { // Read original message }) // After cache is updated state.Handler.AddHandler(func(ev *gateway.MessageCreateEvent) { // Cache already updated }) ``` -------------------------------- ### Get Cached Emoji Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/state.md Fetches a specific emoji from a guild's cache. Returns an error if the emoji is not present in the cache. ```go func (s *State) Emoji(guildID discord.GuildID, emojiID discord.EmojiID) (*discord.Emoji, error) ``` -------------------------------- ### Default Rate Limiter Configuration Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/configuration.md Initializes a new API client using the default rate limiting configuration. This includes per-major-parameter and global rate limiters, with automatic backoff for 429 responses. ```go client := api.NewClient(token) ``` -------------------------------- ### Get All Cached Roles Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/state.md Retrieves a list of all roles within a guild that are currently stored in the cache. No API call is made. ```go func (s *State) Roles(guildID discord.GuildID) ([]discord.Role, error) ``` -------------------------------- ### Get Channel from Cache or API Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/state.md Fetches a specific channel's data, prioritizing the cache and then querying the API if necessary. ```go func (s *State) Channel(channelID discord.ChannelID) (*discord.Channel, error) ``` -------------------------------- ### Create Gateway with Intents Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/configuration.md Creates a gateway connection and specifies the desired gateway intents. This determines which event types the gateway will receive from Discord. ```go gw, err := gateway.NewWithIntents(ctx, "Bot YOUR_TOKEN", gateway.IntentGuilds, gateway.IntentDirectMessages, ) ``` -------------------------------- ### New Gateway with Custom URL and Token Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/gateway.md Creates a Gateway instance allowing for a custom gateway URL and bot token, offering flexibility in connection endpoints. ```go func NewCustom(gatewayURL, token string) *Gateway ``` -------------------------------- ### Handling Session Closed Error Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/errors.md Illustrates how to manage the ErrClosed error, which occurs when attempting to use a closed session or before it has started. ```go var ErrClosed = errors.New("Session is closed") ``` ```go err := sess.Wait(ctx) if err == session.ErrClosed { // Session was never opened or already closed if err := sess.Open(ctx); err != nil { log.Fatal(err) } } ``` -------------------------------- ### Context Say Method Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/utils.md Sends a message to the same channel as the command context. Optionally accepts embeds. ```go func (c *Context) Say(content string, embeds ...discord.Embed) (*discord.Message, error) ``` -------------------------------- ### Get Audit Log Reason Header Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Generates an HTTP header for an audit log reason, returning nil if the reason is empty. ```go func (r AuditLogReason) Header() http.Header ``` -------------------------------- ### CreateGuild Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/client.md Creates a new guild with the provided creation data. ```APIDOC ## CreateGuild ### Description Creates a new guild with the provided creation data. ### Method POST ### Endpoint /guilds ### Parameters #### Request Body - **data** (CreateGuildData) - Required - Data required to create the guild. ``` -------------------------------- ### Get Last Gateway Error Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/gateway.md Returns the last error that caused the gateway to disconnect. This is only valid after the channel returned by Connect has been closed. ```go func (g *Gateway) LastError() error ``` -------------------------------- ### Create New State with Default Store Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/state.md Creates a new state instance with a default in-memory store. Ensure to close the state when done to release resources. ```go state := state.New("Bot YOUR_TOKEN") deferr state.Close() ``` -------------------------------- ### Ready Event Structure Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/gateway.md Defines the structure of the ReadyEvent, sent when the gateway connection is established. ```go type ReadyEvent struct { V int User *discord.User Guilds []discord.GuildID SessionID string ResumeGatewayURL string Shard *Shard Application *discord.Application Unavailable []discord.GuildID } ``` -------------------------------- ### Get Last Sent Heartbeat Time Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/gateway.md Returns the timestamp when the last heartbeat was sent. Returns the zero-value time if no heartbeat has been sent. ```go func (g *Gateway) SentBeat() time.Time ``` -------------------------------- ### Get Channel Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/state.md Retrieves a specific channel by its ID. The data is fetched from the cache first, and if not found, it falls back to querying the API. ```APIDOC ## func (s *State) Channel(channelID discord.ChannelID) (*discord.Channel, error) ### Description Gets a channel from cache or API. ### Parameters - **channelID** (discord.ChannelID) - Required - The ID of the channel to retrieve ### Returns - **(*discord.Channel, error)** - The channel object or an error if retrieval fails ``` -------------------------------- ### Get Guild Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/state.md Retrieves a specific guild by its ID. The data is fetched from the cache first, and if not found, it falls back to querying the API. ```APIDOC ## func (s *State) Guild(guildID discord.GuildID) (*discord.Guild, error) ### Description Gets a guild from cache or API. ### Parameters - **guildID** (discord.GuildID) - Required - The ID of the guild to retrieve ### Returns - **(*discord.Guild, error)** - The guild object or an error if retrieval fails ``` -------------------------------- ### Get Message from Cache or API Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/state.md Fetches a specific message by its ID within a channel. The cache for messages is limited per channel. ```go func (s *State) Message(channelID discord.ChannelID, messageID discord.MessageID) (*discord.Message, error) ``` -------------------------------- ### Create State from Existing Session Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/state.md Constructs a state instance from an already established session and a store. This is useful when integrating state management into an existing session. ```go func NewFromSession(s *session.Session, cabinet *store.Cabinet) *State ``` -------------------------------- ### Get Last Acknowledged Heartbeat Time Source: https://github.com/diamondburned/arikawa/blob/v3/_autodocs/api-reference/gateway.md Returns the timestamp when the last heartbeat was acknowledged by the gateway. Returns the zero-value time if no heartbeat has been acknowledged. ```go func (g *Gateway) EchoBeat() time.Time ```