GoBot

command module
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2025 License: MIT Imports: 4 Imported by: 0

README

GoBot

A personal Discord bot project built with Go, utilizing the DiscordGo library for Discord API integration.

Table of Contents
  1. About
  2. Getting Started
  3. Usage
  4. Features
  5. Command Registration

About

Gobot is a side project of mine which was solely created to understand the "Go" language better.

Built With
  • Go - The programming language used
  • DiscordGo - Go package for Discord API integration
  • GoDotEnv - Environment variable management
  • Docker - Containerization

Getting Started

Prerequisites
Installation
  1. Clone the repository
git clone https://github.com/bluejutzu/GoBot.git
  1. Install dependencies
go mod download
  1. Create a .env file in the root directory with the following:
BOT_TOKEN="your_bot_token_here"

or rename the .env.example to .env and change the BOT_TOKEN value.

Usage

Running Locally
go run main.go
Using Docker
# Build the container
docker build -t gobot .

# Run the container
docker run -d --name gobot --env-file .env gobot
Updating Docker Container

When you make changes to your .env file or any other files, you'll need to rebuild and restart the container:

# Using Docker Compose (recommended):
docker compose down
docker compose up -d --build

# Or using Docker directly:
docker stop gobot
docker rm gobot
docker build -t gobot .
docker run -d --name gobot --env-file .env gobot

Features

  • /ping - Check if the bot is online
  • /what-is-my-id - Get your Discord user ID
  • Working on more features

Command Registration

Commands in GoBot are registered through a structured system:

  1. Command Definition

    • Commands are defined as ApplicationCommand structs in the commands slice
    • Each command specifies its name, description, and any options
  2. Command Handler Mapping

    • Each command has a corresponding handler function in the commandHandlers map
    • Handlers process the command when it's triggered by a user
  3. Registration Process

    • Commands are automatically registered with Discord's API during bot startup
    • The bot creates application_commands for each defined command

Example of how commands are structured:

package misc

// Command definition
var ExampleCommand = &discordgo.ApplicationCommand{
    Name: "example",
    Description: "An example command",
}

// Hanlder function
func HandleExampleCommand(s *discordgo.Session, i *discordgo.InteractionCreate) {
  // ...add code here
}

And in the bot/bot.go file:

// command mapping
commands = []*discordgo.ApplicationCommand {
	misc.ExampleCommand,
}
// Handler mapping
commandHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate) {
	"example": HandleExampleCommand,
}

Command Line Interface (CLI)

Gobot has it's own CLI, named gobot, that has tools and utilities for this certain project. As of now the CLI is available in the repository.

License (MIT)

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
cli
cmd
commands

Jump to

Keyboard shortcuts

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