bolt/README.md

69 lines
2.0 KiB
Markdown
Raw Normal View History

2025-06-04 19:06:53 +00:00
# bolt
2025-06-04 16:00:53 -04:00
Base Discord bot framework
## Introduction
2025-06-04 16:36:11 -04:00
bolt is a wrapper for Discordgo to provide very quick and easy setup for simple Discord bots. The only code required to run bolt is 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.
2025-06-04 16:01:53 -04:00
2025-06-04 16:31:33 -04:00
## Basic Usage
bolt allows developers to create a Discord bot with simply a discord bot token and a few lines of Go code, the below example creates a Discord bot and registers three commands: ".test", ".time", and ".role"
2025-06-04 16:31:33 -04:00
```go
package main
import (
"log"
"os"
"os/signal"
"syscall"
"time"
"code.jakeyoungdev.com/jake/bolt"
_ "github.com/joho/godotenv/autoload"
)
func main() {
b := bolt.New()
b.AddCommands(
2025-06-04 16:36:11 -04:00
// .test can be run at any time by anyone
2025-06-04 16:31:33 -04:00
bolt.Command{
Trigger: ".test",
Payload: func(msg bolt.Message) (res string, err error) {
return "nah", nil //any strings returned will be sent in response to the Discord message
},
},
2025-06-04 16:36:11 -04:00
// .time can be run every 25 seconds by anyone
2025-06-04 16:31:33 -04:00
bolt.Command{
Trigger: ".time",
Payload: func(msg bolt.Message) (res string, err error) {
return "yer", nil
},
2025-06-04 16:36:11 -04:00
Timeout: time.Second * 25,
2025-06-04 16:31:33 -04:00
},
2025-06-04 16:36:11 -04:00
// .role can be run every 10 seconds by anyone with the 'admin' role
bolt.Command{
Trigger: ".role",
Payload: func(msg bolt.Message) (res string, err error) {
return "hi", nil
},
Timeout: time.Second * 10,
Roles: []string{"admin"},
2025-06-04 16:36:11 -04:00
},
2025-06-04 16:31:33 -04:00
)
_ = b.Start()
//set up safe CTRL-C
sigChannel := make(chan os.Signal, 1)
signal.Notify(sigChannel, syscall.SIGINT)
log.Println("bot running")
<-sigChannel
if err := b.Stop(); err != nil {
panic(err)
}
}
```
2025-06-04 16:01:53 -04:00
## Development
bolt is in heavy development at the moment and may break occasionally before a v1 release, it is currently in a testing phase and should not be used until tagged.