Welcome to the official website for Gofluxer. Gofluxer is an API wrapper to make Fluxer.app bots in Go.
The Gofluxer package is not officially endorsed by or affiliated with fluxer.app or the Go programming language
NOTE: This quick start guide was made for gofluxer v0.4.x since this is when this site was last updated. This quick start guide also assumes you are using Linux. Steps for environment setup is a bit different on Windows. Refer to the Go website for additional information on setting up Go on your machine. GoFluxer requires Go 1.21 or newer.
Before doing anything, you will need to install Gofluxer to your Go environment. To do this, you can run the following command:
go get github.com/go-fluxer/gofluxer
or
go get codeberg.org/go-fluxer/gofluxer
Once you have setup a Go environment and have installed gofluxer, follow these steps to create a bot account. These steps assume you are using the official browser client provided by Fluxer. Steps may be a bit different depending on the client used if using a third party client.
Once in your application settings, click on "Regenerate" under a place called "Bot token" to obtain your bot token.
You may be asking, what even is a bot token? A bot token is essentially like a password that your bot uses to log into Fluxer. It is extremely important to never share this token with anyone. If someone managed to get a hold of it, they can do whatever they want with your bot like it is their own bot which means they can do malicious things with it. If someone else has your bot token, they can do things like kick or ban as many people as possible as well as DM spam as many user as possible and spam every server the bot is in
If your bot token has been compromised wheither it is from accidently commiting it to a public repository, posting it in the GoFluxer support server, or other instances where you might see your bot's token in danger, you can press the "Regenerate" button under bot token within your bot's settings (the same way you got your token originally). This will invalidate your old bot token and give you a new one. You will need to update your bot's code with the new token.
To add your bot to a server, within your bot settings, scroll down till you see OAuth2 URL Builder. Check the bot scope and copy the Authorize url that it gave you. They should look something like this: https://web.fluxer.app/oauth2/authorize?client_id=(BOTID)&scope=bot
Now that you made a bot application and you have setup your environment to run Go projects with GoFluxer, we can now get started with making a Fluxer bot.
Here is how you can make a Fluxer.app bot client with the GoFluxer package:
package main
import (
"fmt"
"strings"
// Import the Gofluxer package.
"github.com/go-fluxer/gofluxer"
)
func main() {
// Make the Fluxer.app Bot client.
bot := gofluxer.NewBot("FLUXERBOTTOKEN", "!")
// Replace FLUXERBOTTOKEN with your actual fluxer.app bot token. The "!" part is the bot prefix for the command handler.
// Log into the bot.
fmt.Println("Gofluxer Bot is getting Ready")
if err := bot.Run(); err != nil {
fmt.Printf("Gofluxer Bot stopped: %v\n", err)
}
}
Additional Bot configuration options
package main
import (
"fmt"
"strings"
// Import the Gofluxer package.
"github.com/go-fluxer/gofluxer"
)
func main() {
// Make the Fluxer.app Bot client.
bot := gofluxer.NewBot("FLUXERBOTTOKEN", "!")
bot.NewBotInstance("https://example.com/api/v1", "wss://example.com/gateway/?v=1")
// Use a 3rd party Fluxer instance with NewBotInstance. (Baseurl, WebsocketUrl)
bot.NewBotConfig(true, 500)
// Setup max message caching limits. (EnableMessageCachingLimit, MaxMessageCacheLimit)
// Bot login logic.
}
Within the main() function, you can add events like OnMessage() and AddCommand() to give your Fluxer bot some functionality. Here is an example on how to add these events to your code.
// package main and imports here.
func main() {
// The client line(s)
// OnMessage event
bot.OnMessage(func(m *gofluxer.Message) {
// When someone says a message, it gets logged into the console.
fmt.Printf("[%s]: %s\n", m.Author.Username, m.Content)
// When someone says ping, the bot replies with Pong! without needing the prefix.
if strings.ToLower(m.Content) == "ping" {
bot.SendMessage(m.ChannelID, "Pong!")
}
})
// AddCommand (Command handler).
// SendMessage is normal message. ReplyMessage will reply to the command author.
bot.AddCommand("ping", func(m *gofluxer.Message, args []string) {
bot.SendMessage(m.ChannelID, "Pong!")
})
bot.AddCommand("pingreply", func(m *gofluxer.Message, args []string) {
bot.ReplyMessage(m, "Pong!")
})
// Bot login logic.
}
There are other functions and events that you can use to give your bot functionality. Below is some examples on using some of the other events that GoFluxer has.
// package main and imports here.
func main() {
// The client line(s)
bot.OnUserJoin(func(u *gofluxer.UserJoinPayload) {
fmt.Printf("Welcome %s to %s!\n", u.User.Username, u.GuildID)
})
// OnUserJoin (Triggers when a user joins a server).
bot.OnUserLeave(func(l *gofluxer.UserLeavePayload) {
fmt.Printf("%s (ID: %s) has left %s.\n", l.User.Username, l.UserID, l.GuildName)
})
//OnUserLeave (Triggers when a user leaves a server).
bot.OnMessageDelete(func(d *gofluxer.MessageDeletePayload) {
fmt.Printf("The following message %s was deleted from %s\n", d.MessageID, d.ChannelID)
})
// OnMessageDelete (Triggers when a message gets deleted).
bot.OnMessageEdit(func(e *gofluxer.MessageUpdatePayload) {
if e.OldContent != "" {
fmt.Printf("Message was edited in <#%s>!\nOld content: %s\nNew content: %s\n", e.ChannelID, e.OldContent, e.NewContent)
}
})
// OnMessageEdit (Triggers when a message gets edited). Requires NewBotConfig to be active for this to work.
bot.OnMessageReact(func(e *gofluxer.MessageReactionPayload) {
bot.AddReaction(e.ChannelID, e.MessageID, "👀")
})
// OnMessageReact (Triggers when someone reacts to a message).
// Bot login logic.
}
These are the basics for making a basic Fluxer.app bot in Go using GoFluxer. If you plan to release your Fluxer bot on sites like Github or Codeberg, I advise that you use .env or a config.json file to store your values instead of hard coding the values directly in the code. Obviously don't push any secrets to your repo. If you need help with using the GoFluxer package, feel free to join the GoFluxer Fluxer.app server.