github.com/diamondburned/arikawa/v2@v2.1.0/_example/advanced_bot/main.go (about)

     1  // Package main demonstrates an advanced bot that uses the bot router library to
     2  // make commands.
     3  package main
     4  
     5  import (
     6  	"log"
     7  	"os"
     8  
     9  	"github.com/diamondburned/arikawa/v2/bot"
    10  )
    11  
    12  // To run, do `BOT_TOKEN="TOKEN HERE" go run .`
    13  
    14  func main() {
    15  	var token = os.Getenv("BOT_TOKEN")
    16  	if token == "" {
    17  		log.Fatalln("No $BOT_TOKEN given.")
    18  	}
    19  
    20  	commands := &Bot{}
    21  
    22  	bot.Run(token, commands, func(ctx *bot.Context) error {
    23  		ctx.HasPrefix = bot.NewPrefix("!", "~")
    24  		ctx.EditableCommands = true
    25  
    26  		// Subcommand demo, but this can be in another package.
    27  		ctx.MustRegisterSubcommand(&Debug{})
    28  
    29  		// The bot package will automatically derive out Gateway intents. It
    30  		// might not catch everything though, so a ctx.Gateway.AddIntents is
    31  		// always available.
    32  
    33  		return nil
    34  	})
    35  }