Skip to content
This repository has been archived by the owner on Mar 25, 2022. It is now read-only.
/ ash-router Public archive

A small Discord slash commands wrapper package for DiscordGo.

License

Notifications You must be signed in to change notification settings

mcdearman/ash-router

Repository files navigation

ashrouter

go.dev reference Go Report Card

Getting Started

Installation

go get github.com/mathlet/ashrouter

There's no set architecture but a good way to do it is to put commands in individual files.

Usage

Import:

import "github.com/mathlet/ashrouter"

Create a new router:

router := ashrouter.NewRouter()

Add global commands (call AddGuildCommands if you don't want the commands to be global):

router.AddGlobalCommands(
		ashrouter.Command{
			ApplicationCommand: &discordgo.ApplicationCommand{
				Name:        "ping",
				Description: "Pings the bot",
				Type:        discordgo.ChatApplicationCommand,
			},
			Handler: func(ctx *ashrouter.Context) error {
				err := ctx.InteractionRespond(ctx.Interaction, &discordgo.InteractionResponse{
					Type: discordgo.InteractionResponseChannelMessageWithSource,
					Data: &discordgo.InteractionResponseData{
						Flags:   64,
						Content: fmt.Sprintf("Pong %dms!", ctx.HeartbeatLatency()/time.Millisecond),
					},
				})
				return err
			},
		},
	)

Add default router handlers to session:

router.StartWithDefault()

This should be called before opening the session. You don't have to call this. This just makes it easy if you don't want to setup custom functionality for how the commands are loaded.

For more examples check the examples directory.

About

A small Discord slash commands wrapper package for DiscordGo.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages