Giter Club home page Giter Club logo

bfcord's Introduction

Go Reference

bfcord

Discord API library written in golang with focus on simplicity and performance

EARLY ACCESS / BETA

For this moment we CAN'T guarantee full stability for longer time perspective. The library is actively tested on our multiple bots and by our testers.

Discord Widget

Getting started

Installation

go get github.com/BOOMfinity/bfcord

Basic client example

Bfcord uses options pattern in more complex constructors

// create client
bot, err := client.New("token", client.WithIntents(intents.X|intents.Y) /*other options: client.WithX()*/)

// register events
bot.Sub().Interaction(func(bot client.Client, shard *gateway.Shard, ev *interactions.Interaction) {
    HandleInteraction(bot, cfg, ev) // your implementation
})

bot.Sub().MessageCreate(func(bot client.Client, shard *gateway.Shard, ev discord.Message) {
    HandleMessage(bot, ev) // your implementation
})

// start the client
err = bot.Start(context.Background())
if err != nil {
    panic(err)
}
bot.Wait()

Packages and features

Client (godoc)

Client is an intuitive wrapper over gateway, api and cache packages. It provides convenient methods for interacting with discord, listening for events, and fetching data from API and cache.

Slash (godoc) and Interactive (godoc)

Slash package provides basic API client for managing slash commands

Interactive is a utility package giving easier ways to use and interact with message components (buttons, lists, etc.)

Cache (godoc)

Cache is accessible under client.Store() method. However, you can (should?) use methods built into client whenever possible (ex: bot.Guild(), Channel(), User()), as they automatically fall back to API if object is not in cache yet.

bfcord uses modern and performant stores built with SliceMap approach and generics. This ensures low load on GC while maintaining high performance.

Examples

Pull a guild (using client's method)

guild, err := bot.Guild(613425648685547541).Get()

Pull a guild (cache only)

guild, err := bot.Store().Guilds().Get(613425648685547541)

Find guilds with more than 1000 members

guilds := bot.Store().Guilds().Filter(func(guild discord.BaseGuild) bool {
	return guild.MemberCount > 1000
})

API (godoc)

Note Not all endpoints are implemented at this moment - if something is missing and you need it - notify us

API is accessible under client.API() method, and is split into logical categories. For more complex endpoints builder pattern is used.

Examples

Delete a channel

bot.API().Channel(41514364364367).Delete()

Send a message with embed

msg, err := bot.API().Channel(1654564363426634).SendMessage().Embed(discord.MessageEmbed{
	Description: "example",
	Title:       "example",
}).Execute(bot)

Edit a guild

bot.API().Guild(3213232312312).Edit().Name("new name").Description("new description").AFKChannelID(1232312312414).Execute(bot, "test reason")

Gateway (godoc)

Gateway methods are accessible within client:

Refer to docs for more advanced usage.

Voice

See: godoc of voice package (readme soon)

Modular usage

Each of the packages can be used independently (excl. client). For example, you can grab just the gateway and api package, and write your own logic around it.

Why another library? Is it better than <insert any library here> ?

We don't want to compare ourselves. This library was written because other libraries weren't suitable for our needs (and we wanted to get some experience in golang).

However, we can say that it's probably the most performant and memory efficient discord library right now.

bfcord's People

Contributors

unxcepted avatar venompcpl avatar mrboombastic avatar cyberl1 avatar

Stargazers

Szymon avatar  avatar MysterDead avatar  avatar guam avatar kamil avatar  avatar

Watchers

 avatar Kostas Georgiou avatar

Forkers

minerpl

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.