Categorygithub.com/quakecodes/recv
modulepackage
1.0.1
Repository: https://github.com/quakecodes/recv.git
Documentation: pkg.go.dev

# README

recv

A simple message command library for DiscordGo, inspired by discord.py.

GoDoc

Features

  • Command aliases
  • Argument converters: convert a string input into output of any type
  • Command checks (for permissions etc)
  • Command usage generation
  • Easy to implement in an existing DiscordGo project

Installation

It is assumed that you have Go 1.17 installed.

go get github.com/quakecodes/recv

Usage

A full scale project can be found in the _example folder, including examples for checks and converters


Create a new command router

router := recv.NewCommandRouter()

Add a command

router.AddCommand(recv.Command{
  Name:        "Ping",
  Description: "Sends \"pong\"",
  Callback: func(c *recv.CommandCtx) {
    c.Session.ChannelMessageSend(c.Message.ChannelID, "pong")
  },
})

Process commands in a message

func messageCreate(s *discordgo.Session, m *discordgo.MessageCreate) {
  res, err := router.ProcessCommands(".", s, m)
  if err != nil {
    fmt.Println(err)
    return
  } else if res.Command == nil {
    s.ChannelMessageSend(m.ChannelID, "command not found")
  }
  go res.Callback()
}

# Functions

creates a new CommandRouter.

# Structs

returned when a command check fails.
represents a command that users can use.
argument for a command.
a callback that decides whether a command can be run or not.
stores contextual information for a command such as arguments, session and message.
stores command routes.
returned when a converter doesn't convert input successfully.
a callback that "converts" a string input into something else.
stores contextual information for a converter such as the argument, input, session and message.
stores basic context.
returned when a required argument is missing.
the result of calling ProcessCommands, contains the handler for the function and command that was parsed.