Skip to content

ben-forster/revolt

Repository files navigation

Go Reference Go Report Go Version License Revolt.go Version

Revolt.go

Revolt.go is a Go package for writing bots and self-bots for Revolt.

Features

  • Event listener.
  • Easy to use.
  • Support for self bots.
  • Simple caching system.

Getting Started

Installation

  • Create a new project and initiate the go.mod file. go mod init example
  • Install the package using go get github.com/ben-forster/revolt
  • Create your main bot file. touch main.go

API Reference

Click here for the library's API reference.

Official documentation will come in the near future.

Notice

Please note that you will need Go 1.21 to use this library.

This package is still under development and while you can create a working bot, the library is not finished. You can see a development roadmap here. Please create an issue if you would like to contribute.

Ping Pong Example (Bot)

package main

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

    "github.com/ben-forster/revolt"
)

func main() {
    // Init a new client.
    client := revolt.Client{
        Token: "bot token",
    }

    // Listen a on message event.
    client.OnMessage(func(m *revolt.Message) {
        if m.Content == "!ping" {
            sendMsg := &revolt.SendMessage{}
            sendMsg.SetContent("🏓 Pong!")

            m.Reply(true, sendMsg)
        }
    })

    // Start the client.
    client.Start()

    // Wait for close.
    sc := make(chan os.Signal, 1)

    signal.Notify(
        sc,
        syscall.SIGINT,
        syscall.SIGTERM,
        os.Interrupt,
    )
    <-sc

    // Destroy client.
    client.Destroy()
}

Ping Pong Example (Self-Bot)

package main

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

    "github.com/ben-forster/revolt"
)

func main() {
    // Init a new client.
    client := revolt.Client{
        SelfBot: &revolt.SelfBot{
            Id:           "session id",
            SessionToken: "session token",
            UserId:       "user id",
        },
    }

    // Listen a on message event.
    client.OnMessage(func(m *revolt.Message) {
        if m.Content == "!ping" {
            sendMsg := &revolt.SendMessage{}
            sendMsg.SetContent("🏓 Pong!")

            m.Reply(true, sendMsg)
        }
    })

    // Start the client.
    client.Start()

    // Wait for close.
    sc := make(chan os.Signal, 1)

    signal.Notify(
        sc,
        syscall.SIGINT,
        syscall.SIGTERM,
        os.Interrupt,
    )
    <-sc

    // Destroy client.
    client.Destroy()
}

Credit

This project is a mantained and re-worked version of 5elenay's library revoltgo.