Categorygithub.com/Starshine113/crouter
repositorypackage
0.7.0
Repository: https://github.com/starshine113/crouter.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

crouter

Go Reference

A simple command handler for discordgo.

Usage

import "github.com/Starshine113/crouter"

// ... session initialisation code ...

// create the router
r := crouter.NewRouter(dg, []string{botOwner}, []string{"?", "!"})

// add the message create handler
dg.AddHandler(r.MessageCreate)

// add a command
r.AddCommand(&crouter.Command{
    Name: "Ping",

    Summary: "Check if the bot is running",

    Command: func(ctx *crouter.Ctx) (err error) {
        ping := ctx.Session.HeartbeatLatency().Round(time.Millisecond)
        _, err = ctx.Sendf("Ping! Average latency: %s", ping)
        return err
    },
})

// add intents (or just add crouter.RequiredIntents to your existing intents)
dg.Identify.Intents = discordgo.MakeIntent(crouter.RequiredIntents)

// open the session
err = dg.Open()

// ...

A more complete example can be found in the example/ directory.