bolt
Base Discord bot framework
Introduction
bolt is a wrapper for Discordgo to provide very quick and easy setup for simple Discord bots. The only code required to run bolt are the command handler functions, this provides developers with the ability to have text-based commands on a Discord server without all the bootstrapping and setup usually required. Any strings returned from the Payload function will be sent back to the Discord server as a reply to the command message.
Basic Usage
bolt allows developers to create a Discord bot with a discord bot token and a few lines of Go code, discord tokens must be set as an environment variable labeled DISCORD_TOKEN. The below example creates a Discord bot and registers three commands: ".ping", ".time", and ".role" the "." character is the default command indicator but that can be changed using the WithIndicator option.
package main
import (
"log"
"os"
"os/signal"
"syscall"
"time"
"code.jakeyoungdev.com/jake/bolt"
_ "github.com/joho/godotenv/autoload"
)
func main() {
//bolt defaults the command indicator to '.' however that can be changed with the options
//Example: bolt.New(bolt.WithIndicator('!')) would support commands like !ping
b := bolt.New()
b.AddCommands(
// .ping can be run at any time by anyone and will respond with 'pong'
bolt.Command{
Trigger: "ping",
Payload: func(msg bolt.Message) (string, error) {
return "pong", nil //any strings returned will be sent in response to the Discord message
},
},
// .time can be run every 25 seconds by anyone and will respond with 'yer'
bolt.Command{
Trigger: "time",
Payload: func(msg bolt.Message) (string, error) {
return "yer", nil
},
Timeout: time.Second * 25,
},
// .role can be run every 10 seconds by anyone with the 'admin' role and will respond with 'hi'
bolt.Command{
Trigger: "role",
Payload: func(msg bolt.Message) (string, error) {
return "hi", nil
},
Timeout: time.Second * 10,
Roles: []string{"admin"},
},
)
//start is a blocking call that handles safe-shutdown, all configuration and setup should be done before calling Start()
err := b.Start()
if err != nil {
panic(err)
}
}
Development
bolt is in development at the moment and may break occasionally before a v1 release