Code Monkey home page Code Monkey logo

discordbooter's Introduction

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)
}

discordbooter's People

Contributors

zaskoh avatar

Stargazers

xeno avatar Lubomir Anastasov avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.