disgo

package module
v0.8.4 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2022 License: Apache-2.0 Imports: 7 Imported by: 80

README

Go Reference Go Report Go Version License Disgo Version Disgo Discord

discord gopher

DisGo

DisGo is a Discord API wrapper written in GoLang aimed to be consistent, modular, customizable and higher level than other Discord API wrappers.

Summary

  1. Features
  2. Missing Features
  3. Getting Started
  4. Documentation
  5. Examples
  6. Related Projects
  7. Other GoLang Discord Libraries
  8. Troubleshooting
  9. Contributing
  10. License
Features
Missing Features

Getting Started

Installing
go get github.com/disgoorg/disgo
Building a Disgo Instance
package main

import (
	"github.com/disgoorg/disgo"
	"github.com/disgoorg/disgo/bot"
	"github.com/disgoorg/disgo/discord"
	"github.com/disgoorg/disgo/gateway"
)

func main() {
	client, err := disgo.New("token",
		bot.WithGatewayConfigOpts(
			gateway.WithGatewayIntents(
				discord.GatewayIntentGuilds,
				discord.GatewayIntentGuildMessages,
				discord.GatewayIntentDirectMessages,
			),
		),
	)
}
Full Ping Pong Example
package main

import (
	"context"
	"os"
	"os/signal"
	"syscall"

	"github.com/disgoorg/disgo"
	"github.com/disgoorg/disgo/bot"
	"github.com/disgoorg/disgo/cache"
	"github.com/disgoorg/disgo/discord"
	"github.com/disgoorg/disgo/events"
	"github.com/disgoorg/disgo/gateway"
	"github.com/disgoorg/log"
)

func main() {
	client, err := disgo.New(os.Getenv("token"),
		bot.WithGatewayConfigOpts(
			gateway.WithGatewayIntents(
				discord.GatewayIntentsNone,
			),
		),
		bot.WithCacheConfigOpts(cache.WithCacheFlags(cache.FlagsDefault)),
		bot.WithEventListeners(&events.ListenerAdapter{
			OnMessageCreate: onMessageCreate,
		}),
	)
	if err != nil {
		log.Fatal("error while building disgo: ", err)
	}

	defer client.Close(context.TODO())

	if err = client.ConnectGateway(context.TODO()); err != nil {
		log.Fatal("errors while connecting to gateway: ", err)
	}

	log.Info("example is now running. Press CTRL-C to exit.")
	s := make(chan os.Signal, 1)
	signal.Notify(s, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
	<-s
}

func onMessageCreate(event *events.MessageCreateEvent) {
	var message string
	if event.Message.Content == "ping" {
		message = "pong"
	} else if event.Message.Content == "pong" {
		message = "ping"
	}
	if message != "" {
		_, _ = event.Client().Rest().ChannelService().CreateMessage(event.ChannelID, discord.NewMessageCreateBuilder().SetContent(message).Build())
	}
}
Logging

disgo uses our own small logging lib which provides an interface you can implement. This lib also comes with a default logger which is interchangeable and based on the standard log package. You can read more about it here

Documentation

Documentation is wip and can be found under

  • Go Reference
  • Discord Documentation

Wiki is currently under construction

Examples

You can find examples under _examples

There is also a bot template with commands & db here

or in these projects:

is a standalone audio sending node based on Lavaplayer and JDA-Audio. Allows for sending audio without it ever reaching any of your shards.

Being used in production by FredBoat, Dyno, LewdBot, and more.

is a Lavalink Client which can be used to communicate with LavaLink to play/search tracks

dislog

is a discord webhook logger hook for logrus

Other GoLang Discord Libraries

Troubleshooting

For help feel free to open an issues or reach out on Discord

Contributing

Contributions are welcomed but for bigger changes please first reach out via Discord or create an issue to discuss your intentions and ideas.

License

Distributed under the License . See LICENSE for more information.

Documentation

Index

Constants

View Source
const (
	Name   = "disgo"
	GitHub = "https://github.com/disgoorg/" + Name
)

Variables

View Source
var (
	Version = getVersion()
	OS      = getOS()
)

Functions

func New

func New(token string, opts ...bot.ConfigOpt) (bot.Client, error)

New creates a new core.Client instance with the provided bot token & ConfigOpt(s)

Types

This section is empty.

Jump to

Keyboard shortcuts

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