disgo

package module
v0.0.0-...-481a6b1 Latest Latest
Warning

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

Go to latest
Published: May 20, 2022 License: MIT Imports: 9 Imported by: 0

README

DisGo

DisGo is a powerful Golang library for interacting with Discord.


⚠️ This library is not ready for production use.


Installation

Stable version:
go get -u github.com/denkylabs/disgo
Development version:
$ cd $GOPATH
$ mkdir -p src/github.com/denkylabs
$ cd src/github.com/denkylabs
$ git clone https://github.com/denkylabs/disgo.git
$ cd disgo
$ go install

Example

package main

import "fmt"
import "github.com/denkylabs/disgo"

func main() {
    session, err := disgo.New("Bot token")
    session.Identify.Intents = disgo.CalcIntents("Guilds", "GuildMessages")

    if err != nil {
        fmt.Println(err)
        return
    }

    err = session.Connect()

    if err != nil {
        fmt.Println(err)
        return
    }
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var IntentsFlags = map[string]Intent{
	"Guilds":                 1 << 0,
	"GuildMembers":           1 << 1,
	"GuildBans":              1 << 2,
	"GuildEmojisAndStickers": 1 << 3,
	"GuildIntegrations":      1 << 4,
	"GuildWebhooks":          1 << 5,
	"GuildInvites":           1 << 6,
	"GuildVoiceStates":       1 << 7,
	"GuildPresences":         1 << 8,
	"GuildMessages":          1 << 9,
	"GuildMessageReactions":  1 << 10,
	"GuildMessageTyping":     1 << 11,
	"DirectMessages":         1 << 12,
	"DirectMessageReactions": 1 << 13,
	"DirectMessageTyping":    1 << 14,
	"MessageContent":         1 << 15,
	"GuildScheduledEvents":   1 << 16,
}

A map of intents to their bitfield value Reference: https://canary.discord.com/developers/docs/topics/gateway#gateway-intents

fmt.Println(IntentsFlags["Guilds"])

Functions

This section is empty.

Types

type GatewayHeartbeatSendPacket

type GatewayHeartbeatSendPacket struct {
	Op   int   `json:"op"`
	Data int64 `json:"d"`
}

Packet structures

type GatewayIdentifySendPacket

type GatewayIdentifySendPacket struct {
	Op   int      `json:"op"`
	Data Identify `json:"d"`
}

type Identify

type Identify struct {
	// Token used to start a new session
	Token          string     `json:"token"`
	Intents        Intent     `json:"intents"`
	ShardID        int        `json:"shard_id"`
	ShardCount     int        `json:"shard_count"`
	Compress       bool       `json:"compress"`
	LargeThreshold int        `json:"large_threshold"`
	Properties     Properties `json:"properties"`
}

A structure representing a Discord session

type Intent

type Intent uint64

func CalcIntents

func CalcIntents(intents ...string) (Intent, error)

Calculates the bitfield value for the given intents

intents, err := CalcIntents("Guilds", "GuildMembers")

type Properties

type Properties struct {
	Browser string `json:"$browser"`
	Device  string `json:"$device"`
	Os      string `json:"$os"`
}

A structure representing the properties of a Identify object

type Session

type Session struct {
	// The Identify structure of this session
	Identify Identify `json:"identify"`
	// contains filtered or unexported fields
}

func New

func New(botToken string) (s *Session)

The main hub for interacting with the Discord API, and the starting point for any bot

s := disgo.New("My bot token")

func (*Session) AddListener

func (*Session) AddListener(eventName string, handler func(data map[string]interface{}))

Add a Discord event handler

	func ReadyEvent(data map[string]interface{}) {
 	fmt.Println("Bot is ready!")
	}
	session.AddListener("READY", ReadyEvent)

func (*Session) Connect

func (s *Session) Connect() (e error)

Logs the client in, establishing a WebSocket connection to Discord This function blocks until the connection is lost, ended or an error occurs

s := disgo.New("My bot token")
err := s.Connect()

func (*Session) RemoveListener

func (*Session) RemoveListener(eventName string)

Remove a Discord event handler

session.RemoveListener("READY")

Jump to

Keyboard shortcuts

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