Documentation ¶
Overview ¶
Package bridge is a library to bridge communications with discord.
import bridge "github.com/StalkR/discordgo-bridge"
Setup:
- create a new application: https://discordapp.com/developers/applications/me
- get client ID, required to add bot to server below
- click add bot
- get token, required to configure the bot
- enable server members intent, so it can find avatar and nicknames
- add bot to server: https://discordapp.com/oauth2/authorize?&client_id=CLIENT_ID&scope=bot&permissions=0
- for each channel configure a webhook, required to configure the channels (allows impersonation)
Multiple channels can be bridged. The bot can only be added to one server. To use it on more than one server, create another application and run another bot.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ErrNotConnected = errors.New("not connected")
ErrNotConnected is returned when sending but the bot is not connected.
Functions ¶
This section is empty.
Types ¶
type Bot ¶
type Bot struct {
// contains filtered or unexported fields
}
A Bot represents a discord bridge bot.
Example ¶
general := NewChannel("#general", "https://discord.com/api/webhooks/<webhook id>/<webhook token>", func(nick, text string) { log.Printf("relaying from discord -> external: <%v> %v", nick, text) // implement sending to external }) go func() { // implement receiving from external for ; ; time.Sleep(10 * time.Second) { nick, text := "timebot", fmt.Sprintf("Current time: %v", time.Now()) log.Printf("relaying from external -> discord: <%v> %v", nick, text) general.Send(nick, text) } }() b := NewBot("<bot token>", general) if err := b.Start(); err != nil { log.Fatal(err) } defer b.Close() log.Printf("Discord bridge bot running - press CTRL-C to exit") sc := make(chan os.Signal, 1) signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill) <-sc
Output:
type Channel ¶
type Channel struct {
// contains filtered or unexported fields
}
A Channel represents a discord channel bridge.
func NewChannel ¶
NewChannel creates a new channel bridge. The receive function is called when messages are received on discord.
Click to show internal directories.
Click to hide internal directories.