Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.
/ discordgoext Public archive

Discordgo, but with some extra things you might like.

License

Notifications You must be signed in to change notification settings

Moonlington/discordgoext

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

discordgoext

standard-readme compliant Patreon

Deprecation notice

It's been two years since I have worked on this project. I'm not even sure if it still works. Given the new additions to the Discord API and future bots' reliance on them for their functionality, I have created a new and improved project called Harmonia. Please use that module instead.

Current features

  • Easier way of creating commands for a bot
  • Automatic help command

Table of Contents

Install

go get -u github.com/Moonlington/discordgoext

Usage

Here's an example of a bot that pings and pongs;

package main

import (
    "fmt"
    "os"
    "os/signal"
    "syscall"

    "github.com/Moonlington/discordgoext"
)

func main() {

    // Create a new Discord session using the provided bot token.
    sess, err := discordgoext.New("Bot " + "INSERT YOUR BOT TOKEN", "pingbot.", false)
    if err != nil {
        fmt.Println("error creating Discord session,", err)
        return
    }

    sess.AddCommand("Pings", discordgoext.NewCommand("ping", "Pings", "", "", func(ctx *discordgoext.Context) {
        ctx.SendMessage("pong!")
    }))
    sess.AddCommand("Pongs", discordgoext.NewCommand("pong", "Pongs", "", "", func(ctx *discordgoext.Context) {
        ctx.SendMessage("ping!")
    }))

    sess.AddCommand("Saying Hi", discordgoext.NewCommand(
        "hi",
        "Says hi",
        "[to who]",
        "If `to who` is not provided, it will say hi to you.",
        func(ctx *discordgoext.Context) {
            if len(ctx.Argstr) != 0 {
                ctx.SendMessage("Hi " + ctx.Argstr + "!")
            } else {
                ctx.SendMessage("Hi " + ctx.Mess.Author.Username + "!")
            }
        },
    ))

    // Open a websocket connection to Discord and begin listening.
    err = sess.Open()
    if err != nil {
        fmt.Println("error opening connection,", err)
        return
    }

    // Wait here until CTRL-C or other term signal is received.
    fmt.Println("Bot is now running.  Press CTRL-C to exit.")
    sc := make(chan os.Signal, 1)
    signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
    <-sc

    // Cleanly close down the Discord session.
    sess.Close()
}

Contribute

PRs accepted.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © Moonlington

About

Discordgo, but with some extra things you might like.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages