discog

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2024 License: BSD-3-Clause, MIT Imports: 6 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Discog

DiscordGo logo

Discog is a Go package and a discord bot library which uses Discordgo to interact with Discord API.

Discog provides a boilerplate less way to build discord bot. It has following features :

  • Command manager
  • Interaction Manager
  • Handlers

For help with this package or general Go discussion, please join the Discog Discord Server chat server.

Getting Started

Installing

Discog uses Discordgo so it's important to upto date with Discordgo version for Discog which is v0.28.1

go get will always pull the latest tagged release from the master branch.

go get github.com/kisshan13/discog
Usage

Import the package into your project.

package main

import (
	"log"

	"github.com/bwmarrin/discordgo"
	discog "github.com/kisshan13/discog"
	commands "command"
)

func main() {

	manager := commands.GetManager()
	bot, err := discog.NewBot("<token-here>", manager)

	if err != nil {
		panic(err)
	}

	bot.OnReady(func(r *discordgo.Ready) {
		log.Printf("Bot has connected to Discord as %s (%s)\n", r.User.Username, r.User.ID)
	})

	bot.Run(func(session *discordgo.Session, err error) {
		if err != nil {
			panic(err)
		}
		log.Println("Bot is running")
	})
}

For more information & documentation please visit examples repo .

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEmbedFields

func NewEmbedFields(name string, value string, isInline bool) *discordgo.MessageEmbedField

Returns the Field for the MessageEmbed

func NewEmbedFooter

func NewEmbedFooter(text string, iconUrl string) *discordgo.MessageEmbedFooter

Returns the Footer for the MessageEmbed

func NewEmbedImage

func NewEmbedImage(url string, width int, height int) *discordgo.MessageEmbedImage

Returns the Image for the MessageEmbed

func NewEmbedProvider

func NewEmbedProvider(url string, name string) *discordgo.MessageEmbedProvider

Returns the Provider for the MessageEmbed

func NewEmbedThumbnail

func NewEmbedThumbnail(url string, width int, height int) *discordgo.MessageEmbedThumbnail

Returns the Thumbnail for the MessageEmbed

func NewEmbedVideo

func NewEmbedVideo(url string, width int, height int) *discordgo.MessageEmbedVideo

Returns the Video for the MessageEmbed

Types

type ActionRow

type ActionRow struct {
	// contains filtered or unexported fields
}

Represent a ActionRow

func NewActionRow

func NewActionRow() *ActionRow

Creates a new ActionRow

func (*ActionRow) AddComponent

func (r *ActionRow) AddComponent(component Component) error

Adds a component to the ActionRow

func (*ActionRow) GetComponent

func (r *ActionRow) GetComponent() interface{}

Method used to get the ActionRow components which represent a discordgo.ActionsRow structure

type Bot

type Bot struct {
	CommandManager *CommandManager
	Session        *discordgo.Session
	// contains filtered or unexported fields
}

Bot is the main struct for interacting with Discord. It holds the bot's token and command manager.

func NewBot

func NewBot(token string, manager *CommandManager) (*Bot, error)

NewBot creates a new Bot with the provided token and command manager.

func (*Bot) OnReady

func (b *Bot) OnReady(callback func(r *discordgo.Ready))

OnReady is a callback function that is called when the bot is ready. It logs the bot's status and registers the interaction handlers.

func (*Bot) Run

func (b *Bot) Run(callback func(session *discordgo.Session, err error))

Run starts the Discord bot with the provided callback function.

type Button

type Button struct {
	// contains filtered or unexported fields
}

Represents a Button Component

func NewButton

func NewButton() *Button

Creates a new Button Component

func (*Button) AnyEmoji

func (b *Button) AnyEmoji(emoji Emoji) *Button

Adds emoji to the Button Component

func (*Button) GetComponent

func (b *Button) GetComponent() interface{}

Returns the Button Component

func (*Button) SetDisabled

func (b *Button) SetDisabled() *Button

Disabled the button.

func (*Button) SetID

func (b *Button) SetID(id string) *Button

Sets ID for the button.

func (*Button) SetLabel

func (b *Button) SetLabel(label string) *Button

Adds label to Button.

func (*Button) SetStyle

func (b *Button) SetStyle(style discordgo.ButtonStyle) *Button

Adds style to the Button Component

func (*Button) SetURL

func (b *Button) SetURL(url string) *Button

Sets URL for the button.

type CommandGroup

type CommandGroup struct {
	Name          string
	Description   string
	GuildId       string
	SlashCommands []*SlashCommand
	// contains filtered or unexported fields
}

Command Group to manage related commands like grouping a set of commands for a guild,moderation, utils, user etc.

func NewCommandGroup

func NewCommandGroup(name string, description string, guildId string) *CommandGroup

Creates a new Command Group with the given name, description, and Guild ID.

func (*CommandGroup) AddCommand

func (cg *CommandGroup) AddCommand(command *SlashCommand)

Adds a Slash Command to the command group.

type CommandManager

type CommandManager struct {
	// contains filtered or unexported fields
}

Represents a root command manager for the bot. It holds all the information needed to create & execute commands.

func NewCommandManager

func NewCommandManager() *CommandManager

Creates a new instance of CommandManager.

func (*CommandManager) AddGroup

func (cm *CommandManager) AddGroup(group *CommandGroup)

Adds a command group to the command manager.

func (*CommandManager) AddMessageComponentInteractionHandler

func (cm *CommandManager) AddMessageComponentInteractionHandler(handler func(c *Ctx))

func (*CommandManager) AddModalInteractionHandler

func (cm *CommandManager) AddModalInteractionHandler(handler func(c *Ctx))

func (*CommandManager) FindCommand

func (cm *CommandManager) FindCommand(name string) func(ctx *Ctx)

Finds a command by its name. Returns the handler function if found, nil otherwise.

type Component

type Component interface {
	GetComponent() interface{}
}

type Ctx

type Ctx struct {
	Session     *discordgo.Session           // Client Session
	Interaction *discordgo.InteractionCreate // Interaction Create struct
	// contains filtered or unexported fields
}

Represents callback ctx for Slash Command Handlers

func (*Ctx) FlagEphemeral

func (c *Ctx) FlagEphemeral() *Ctx

Flags the interaction response as ephemeral.

func (*Ctx) FlagReply

func (c *Ctx) FlagReply(flag discordgo.MessageFlags) *Ctx

Adds message flags to the response.

func (*Ctx) Send

func (c *Ctx) Send() error

Sends the response to Discord.

func (*Ctx) SetComponents

func (c *Ctx) SetComponents(actionRows []Component) (*Ctx, error)

Adds the components to the interaction response.

func (*Ctx) SetContent

func (c *Ctx) SetContent(content string) *Ctx

Sets the content of the interaction response.

func (*Ctx) SetCustomID

func (c *Ctx) SetCustomID(id string) *Ctx

Adds a customId to the interaction response

func (*Ctx) SetFiles

func (c *Ctx) SetFiles(files []*discordgo.File) *Ctx

Adds Files to the interaction response.

func (*Ctx) SetMessageEmbeds

func (c *Ctx) SetMessageEmbeds(embeds []*discordgo.MessageEmbed)

Sets message embeds to the interaction response.

func (*Ctx) SetResponseType

func (c *Ctx) SetResponseType(responseType discordgo.InteractionResponseType) *Ctx

Sets the Interaction response type .

func (*Ctx) SetTTS

func (c *Ctx) SetTTS() *Ctx

Sets the Text-To-Speech as true

func (*Ctx) SetTitle

func (c *Ctx) SetTitle(title string) *Ctx

Sets the title for the response.

type Emoji

type Emoji struct {
	// contains filtered or unexported fields
}

Represents an Emoji

func NewEmoji

func NewEmoji(name string, animated bool, id string) *Emoji

Create a new Emoji

type MessageEmbed

type MessageEmbed struct {
	// contains filtered or unexported fields
}

Represents a message embed.

func NewMessageEmbed

func NewMessageEmbed() *MessageEmbed

Returns a MessageEmbed struct

func (*MessageEmbed) GetComponent

func (m *MessageEmbed) GetComponent() *discordgo.MessageEmbed

Returns the discordgo.MessageEmbed struct

func (*MessageEmbed) SetAuthor

func (m *MessageEmbed) SetAuthor(author *discordgo.MessageEmbedAuthor) *MessageEmbed

Sets Author for the message embed

func (*MessageEmbed) SetColor

func (m *MessageEmbed) SetColor(color int) *MessageEmbed

Sets Color for the message embed

func (*MessageEmbed) SetDescription

func (m *MessageEmbed) SetDescription(description string) *MessageEmbed

Sets Description for the message embed

func (*MessageEmbed) SetFields

func (m *MessageEmbed) SetFields(fields []*discordgo.MessageEmbedField) *MessageEmbed

// Sets Fields for the message embed

func (*MessageEmbed) SetFooter

func (m *MessageEmbed) SetFooter(footer *discordgo.MessageEmbedFooter) *MessageEmbed

Sets Footer for the message embed

func (*MessageEmbed) SetImage

Sets Image for the message embed

func (*MessageEmbed) SetProvider

func (m *MessageEmbed) SetProvider(provider *discordgo.MessageEmbedProvider) *MessageEmbed

Sets Provider for the message embed

func (*MessageEmbed) SetThumbnail

func (m *MessageEmbed) SetThumbnail(thumbnail *discordgo.MessageEmbedThumbnail) *MessageEmbed

Sets Thumbnail for the message embed

func (*MessageEmbed) SetTimestamp

func (m *MessageEmbed) SetTimestamp(timestamp string) *MessageEmbed

Sets Timestamp for the message embed

func (*MessageEmbed) SetTitle

func (m *MessageEmbed) SetTitle(title string) *MessageEmbed

Sets Title for the message embed

func (*MessageEmbed) SetType

func (m *MessageEmbed) SetType(embedType discordgo.EmbedType) *MessageEmbed

Sets type for the message embed

func (*MessageEmbed) SetURL

func (m *MessageEmbed) SetURL(url string) *MessageEmbed

Sets URL for the message embed

func (*MessageEmbed) SetVideo

Sets Video for the message embed

type MessageEmbedAuthor

type MessageEmbedAuthor struct {
	// contains filtered or unexported fields
}

Represents a message embed auth

func NewEmbedAuthor

func NewEmbedAuthor(author string) *MessageEmbedAuthor

Returns the MessageEmbedAuthor struct

func (*MessageEmbedAuthor) GetComponent

func (a *MessageEmbedAuthor) GetComponent() interface{}

Returns the discordgo.MessageEmbedAuthor

func (*MessageEmbedAuthor) SetIcon

func (a *MessageEmbedAuthor) SetIcon(icon string) *MessageEmbedAuthor

Sets Icon for the MessageEmbedAuthor

func (*MessageEmbedAuthor) SetURL

Sets URL for the MessageEmbedAuthor

type SelectMenu

type SelectMenu struct {
	// contains filtered or unexported fields
}

Represents a SelectMenu

func NewSelectMenu

func NewSelectMenu(menuType discordgo.SelectMenuType) *SelectMenu

Create a new SelectMenu

func (*SelectMenu) AddChannelTypes

func (sm *SelectMenu) AddChannelTypes(channelTypes []discordgo.ChannelType) *SelectMenu

Add channel types to Select Menu.

func (*SelectMenu) AddDefaultValue

func (sm *SelectMenu) AddDefaultValue(id string, valueType discordgo.SelectMenuDefaultValueType) *SelectMenu

Sets Default value for the SelectMenu

func (*SelectMenu) AddID

func (sm *SelectMenu) AddID(id string) *SelectMenu

Adds an ID to the select menu.

func (*SelectMenu) AddOptions

func (sm *SelectMenu) AddOptions(options []SelectMenuOption) *SelectMenu

Adds options to the select menu

func (*SelectMenu) GetComponent

func (sm *SelectMenu) GetComponent() interface{}

returns the SelectMenu component.

func (*SelectMenu) PlaceHolder

func (sm *SelectMenu) PlaceHolder(placeholder string)

Adds placeholder to select menu

func (*SelectMenu) SetMinMax

func (sm *SelectMenu) SetMinMax(min int, max int) *SelectMenu

Sets Min & Max values for SelectMenu

type SelectMenuOption

type SelectMenuOption struct {
	// contains filtered or unexported fields
}

Represents a SelectMenuOption

func NewSelectMenuOption

func NewSelectMenuOption(label string, value string, description string) *SelectMenuOption

Creates a new SelectMenuOption

func (*SelectMenuOption) AnyEmoji

func (sm *SelectMenuOption) AnyEmoji(emoji *Emoji) *SelectMenuOption

Adds emoji to options

func (*SelectMenuOption) Default

func (sm *SelectMenuOption) Default() *SelectMenuOption

Mark the option as default selected for the SelectMenu

func (*SelectMenuOption) GetComponent

func (sm *SelectMenuOption) GetComponent() discordgo.SelectMenuOption

type SlashCommand

type SlashCommand struct {
	Command *discordgo.ApplicationCommand // Slash Command information
	Handler func(ctx *Ctx)                // Handler function to handle any interaction
}

Represents a Slash Command for the bot

func NewSlashCommand

func NewSlashCommand(command discordgo.ApplicationCommand) *SlashCommand

Creates a new Slash Command

func (*SlashCommand) SetHandler

func (c *SlashCommand) SetHandler(handler func(ctx *Ctx))

Sets handler for the command

type TextInput

type TextInput struct {
	// contains filtered or unexported fields
}

func NewTextInput

func NewTextInput(id string) *TextInput

func (*TextInput) GetComponent

func (t *TextInput) GetComponent() interface{}

func (*TextInput) Required

func (t *TextInput) Required() *TextInput

func (*TextInput) SetLabel

func (t *TextInput) SetLabel(label string) *TextInput

func (*TextInput) SetMinMax

func (t *TextInput) SetMinMax(min int, max int) *TextInput

func (*TextInput) SetPlaceholder

func (t *TextInput) SetPlaceholder(placeholder string) *TextInput

func (*TextInput) SetStyle

func (t *TextInput) SetStyle(style discordgo.TextInputStyle) *TextInput

func (*TextInput) SetValue

func (t *TextInput) SetValue(value string) *TextInput

Jump to

Keyboard shortcuts

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