A modular Golang Discord API Wrapper

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. Stability
  2. Features
  3. Missing Features
  4. Getting Started
  5. Documentation
  6. Examples
  7. Other interesting Projects to look at
  8. Other GoLang Discord Libraries
  9. Troubleshooting
  10. Contributing
  11. License

Stability

The public API of DisGo is mostly stable at this point in time. Smaller breaking changes can happen before the v1 is released.

After v1 is released breaking changes may only happen if the Discord API requires them. They tend to break their released API versions now and then. In general for every new Discord APi version the major version of DisGo should be increased and with that breaking changes between non major versions should be helt to a minimum.

Features

Missing Features

Getting Started

Installing

go get github.com/disgoorg/disgo

Building a DisGo Instance

Build a bot client to interact with the discord api

package main

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

func main() {
    client, err := disgo.New("token",
        // set gateway options
        bot.WithGatewayConfigOpts(
            // set enabled intents
            gateway.WithGatewayIntents(
                discord.GatewayIntentGuilds,
                discord.GatewayIntentGuildMessages,
                discord.GatewayIntentDirectMessages,
            ),
        ),
        // add event listeners
        bot.WithEventListenerFunc(func(e *events.MessageCreateEvent) {
            // event code here
        }),
    )
}

Full Ping Pong Example

This example can also be found [here]https://github.com/disgoorg/disgo/blob/development/_examples/ping_pong/example.go()

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.GatewayIntentGuildMessages,
                discord.GatewayIntentMessageContent,
            ),
        ),
        bot.WithEventListenerFunc(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)
    <-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().CreateMessage(event.ChannelID, discord.NewMessageCreateBuilder().SetContent(message).Build())
    }
}

Logging

DisGo uses our own small logging interface which you can use with most other logging libaries. This lib also comes with a default logger which is based on the standard log package.

Documentation

Documentation is wip and can be found under

  • Go Reference
  • Discord Documentation

GitHub Wiki is currently under construction. We appreciate help here.

Examples

You can find examples here

There is also a bot template with commands & db here

or in these projects:

Other interesting Projects to look at

Lavalink

Is a standalone audio sending node based on Lavaplayer and JDA-Audio. Which allows for sending audio without it ever reaching any of your shards. Lavalink can be used in combinatio with DisGolink for music Bots

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

DisGolink

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 we recommend first reaching out via Discord or create an issue to discuss your problems, intentions and ideas.

License

Distributed under the License . See LICENSE for more information.

Comments
  • Deadlock Bug

    Deadlock Bug

    After testing I found that rateLimiterImpl.doCleanup will delete expired buckets. Webhook limits 30 requests per minute. It will cause high concurrency. Because b.mu.CLock is locked. However, the deletion of expired buckets causes the previous request UnlockBucket to fail. Subsequent requests will be deadlocked.

  • webhook.Newclient

    webhook.Newclient

    Describe the bug A clear and concise description of what the bug is.

    Error The error which gets logged if there is any:

    import "github.com/disgoorg/disgo/webhook"
    
    client := webhook.NewClient(snowflake.ID("webhookID"), "webhookToken")
    
    message, err := client.CreateEmbeds(discord.NewEmbedBuilder().
    	SetDescription("hello world!").
    	Build(),
    )
    

    Expected behavior Send embeded webhook

    Additional context undefined: webhook.Newclient

  • Bump github.com/DisgoOrg/disgo from 0.3.2 to 0.3.3 in /example

    Bump github.com/DisgoOrg/disgo from 0.3.2 to 0.3.3 in /example

    Bumps github.com/DisgoOrg/disgo from 0.3.2 to 0.3.3.

    Commits
    • d4c3991 Merge pull request #18 from DisgoOrg/development
    • f6e8b5c Merge branch 'master' into development
    • 1f6bb92 moved some metods to interaction & added form-data support to rest-client
    • e6e8eee or maybe not for now
    • 92913ba interaction should have a disgo reference & we should return status 200 lol
    • f25a3ae last fix for interaction webhooks
    • 3d326f1 this should not be a pointer
    • fd6476c fixed not working webhook interactions
    • 6b45240 fixes gatewayintent rename
    • 01dd5d6 Merge pull request #15 from DisgoOrg/dependabot/go_modules/example/github.com...
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • Add

    Add "rest.retryWithDelay()" function?

    if my program restarts immediately after reaching the text per minute webhook limit, will disgoorg automatically wait after the restart to send the messages or will it just throw a 429 error?

    If it throws 429 error, what's the workaround? Probably a func that can wait for a specified time between requests?

  • fix time formatting error with different timezones

    fix time formatting error with different timezones

    Hello!

    The timezone is not parsed with +00:00 format string at discord/time.go#11. This caused my embed message timestamp to display incorrectly. So I changed it to support various timezone. Please check this issue!

    Thank you.

  • request opts

    request opts

    this aims to make it possible to add modifiers to requests like context.Context, X-Audit-Log-Reason and possible other stuff in the future

    Additionally usecases:

    • Checks
    • Request delay
  • reformat well everything

    reformat well everything

    Todos for v1:

    • [ ] finish READMEs
    • [ ] add missing docs(also to interfaces!)
    • [x] Implement missing gateway handlers
    • [ ] implement threads
    • [ ] presence stuff
    • [ ] add more examples
    • [ ] cleanup examples
    • [x] sharding
    • [x] oauth2 support
    • [x] finish rest service interfaces & implementations
    • [x] cleanup cache interfaces (maybe simplify/shorten it?)
    • [x] cache implementations
    • [x] ~~introduce interfaces for all core entities~~
    • [x] think about hiding/exposing implementations
    • [x] finish stage instance implementation
    • [x] hide implementations
    • [x] stickers
    • [x] role icons
  • Bump github.com/DisgoOrg/restclient from 1.1.5 to 1.2.0

    Bump github.com/DisgoOrg/restclient from 1.1.5 to 1.2.0

    Bumps github.com/DisgoOrg/restclient from 1.1.5 to 1.2.0.

    Release notes

    Sourced from github.com/DisgoOrg/restclient's releases.

    v1.2.0

    renamed NewRestError to NewError added noinspect rules added QueryValues custom type

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
  • simple command, autocomplete, component & modals handler

    simple command, autocomplete, component & modals handler

    Features to discuss/consider:

    • [x] support for middlewares
    • [x] support for grouping of handlers
    • [x] support passing data in custom ids for modals & components
discord bot that plays music in a voice channel discord

Music discord bot by serje3 Description A bot written in the Golang language plays music on your server's voice channel on Discord. It can be built an

Nov 17, 2021
A simple Discord bot developed for the Bedrock Gophers discord server.

Bedrock Gopher A simple Discord bot developed for the Bedrock Gophers discord server. Click here to invite the bot to your guild. You will also need t

Mar 12, 2022
Discord-dl: a tool to archive discord channels

discord-dl discord-dl is a tool to archive discord channels. I think it's safe t

May 18, 2022
Discord-notif - Send notifications to discord in Your pipelines or scripts
Discord-notif - Send notifications to discord in Your pipelines or scripts

discord-notif Send notifications to discord in Your pipelines or scripts install

Dec 15, 2022
Discord-finder - The back-end for retrieving information about people on discord
Discord-finder - The back-end for retrieving information about people on discord

About This is the backend application for Discord Finder, it allows you to retrive information about people on discord just like the discord lookup we

Jan 4, 2022
Wipe-discord - TUI application to erase Discord messages
Wipe-discord - TUI application to erase Discord messages

wipe-discord Terminal user interface (TUI) application to delete Discord message

Aug 21, 2022
An high level discord interactions wrapper, simple, clean, extensible. Based on outgoing webhooks.

corde corde is a discord webhook callback API wrapper. It's nowhere near prod-ready, but it's honestly usable, and it's open to contributions. Be awar

Oct 13, 2022
Golang telegram bot API wrapper, session-based router and middleware

go-tgbot Pure Golang telegram bot API wrapper generated from swagger definition, session-based routing and middlewares. Usage benefits No need to lear

Nov 16, 2022
Harmony is a peaceful Go module for interacting with Discord's API

Harmony Harmony is a peaceful Go module for interacting with Discord's API. Although this package is usable, it still is under active development so p

Sep 18, 2022
DiscordGo: a Go package that provides low level bindings to the Discord chat client API
DiscordGo: a Go package that provides low level bindings to the Discord chat client API

DiscordGo DiscordGo is a Go package that provides low level bindings to the Discord chat client API. DiscordGo has nearly complete support for all of

Dec 14, 2021
Twitchbot - Go Twitch Bot Api wrapper, with an easy to use interface.

twitchbot Go Twitch Bot Api wrapper, with an easy to use interface. Example package main import ( "twitch/twitchbot" ) func main() { bot := twitch

Jan 8, 2022
discord exploit tools written in golang

The ultimate CLI tool for TiKV

Aug 19, 2021
Bot para o discord escrito em Golang durante o workshop ministrado na Codecon 2021

Codecon Bot Bot para o discord escrito em Golang durante o workshop ministrado na Codecon 2021 Primeiramente no arquivo main.go coloque o TOKEN do bot

Oct 4, 2021
An easy-to-use discord bot template written in golang using discordgo

Discord Bot An easy-to-use discord bot template written in golang using discordgo. This template was written for learning golang. It will be updated a

Oct 30, 2021
Discord Bot written in Go. Created for 'Intro to Golang', Fall 21

goDiscordBot Discord Bot written in Go. Created for 'Intro to Golang', Fall 21 Session where we coded the bot (goes over setup steps): https://gdsc.co

Nov 3, 2021
Discord Bot in Golang
Discord Bot in Golang

Discord Bot in Golang. In this we will be creating a simple discord bot which retur **pong** when we type **ping** . For this you have to be admin of

Dec 19, 2022
Discord Nitro sniper Written in Golang
Discord Nitro sniper Written in Golang

Discord Nitro sniper Written in GO lang ?? Wow this looks like Slows Sniper Maybe the same src ?? Features Multiple accounts support to claim on one m

Jan 10, 2022
A REALLY crappy discord bot with golang

DiscordTubeFeeder This is some shitty discord bot that looks at a youtube xml fe

Dec 18, 2021
An discord-bot written in golang.

discord-bot I wanted to experiment controlling my "smart" lights at home with a chat bot interface. Originally wanted to use Google Chat for this task

Jan 7, 2022