discordbooter

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2022 License: MIT Imports: 4 Imported by: 3

README

discordbooter

Go reference GitHub Workflow Status Go Report Card go version license GitHub Release

discordbooter is a package that extends discordgo to spin up a discord bot to log or consume messages from / to a discord channel.

Getting started

Installing
go get github.com/zaskoh/discordbooter

To get started you need a discord bot and a token from discord. Follow these articles to prepare it.

Info

The bot will run as a goroutine. To handle the shutdown gracefully you need a context and a waitgroup.

An example how to use it can be found under examples.

Example
go run example/example.go --token xxx --channel yyy
Usage
Import the package into your project
import "github.com/zaskoh/discordbooter"
Start the bot
err := discordbooter.Start(ctx, &wg, *token)
if err != nil {
    log.Fatalf("booting failed %s", err)
}
Add handlers
// define a function you want to add
func discord_handler_x(s *discordgo.Session, m *discordgo.MessageCreate){
	// code goes here
}
// define an array of handlers
var handlers = []interface{}{
    func(s *discordgo.Session, r *discordgo.Ready) { 
        log.Println("discord bot started") 
    }, 
    discord_handler_x,
}

// add them
err = discordbooter.AddHandlers(handlers)
if err != nil {
    log.Printf("unable to add handlers: %s", err)
}
Send message
err := discordbooter.SendMessage(*channel, "hello world!")
if err != nil {
    log.Printf("unable to send message: %s", err)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddHandlers

func AddHandlers(handlers []interface{}) error

AddHandlers to consume messages sent or received in discord

func SendMessage

func SendMessage(channel string, message string) error

SendMessage to a specific discord channel

func Start

func Start(ctx context.Context, wg *sync.WaitGroup, token string) error

Start a new discord bot - only one session is possible

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL