Skip to content

Latest commit

 

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AngloLex

AngloLex is a Discord bot for word discovery, definitions, etymology, and daily vocabulary posts.

The bot registers Discord slash commands that let users fetch a word of the day, define a word, and find a suitable word for a given sentence. It uses Wordnik for word data and OpenAI for the sentence-to-word feature.

Tech stack

  • Go 1.23.3
  • DiscordGo
  • Wordnik API
  • OpenAI API
  • godotenv for environment variable loading
  • gocron for scheduled daily posting
  • PM2 support via ecosystem.config.cjs

Features

  • Discord slash command registration
  • /word-of-the-day command
  • /define command with definitions and etymology
  • /find-word-for command powered by OpenAI
  • Daily Wordnik word-of-the-day posting to a configured Discord channel
  • Wordnik etymology formatting for Discord-friendly output
  • PM2 process config for running the compiled bot

Discord commands

/word-of-the-day

Fetches the current word of the day from Wordnik and posts it in Discord.

The response includes:

  • The word
  • A definition
  • An example usage, when available

/define

Looks up a word using Wordnik.

Option

Name Type Required Description
word string yes The word to define

The response includes:

  • Up to 3 definitions
  • Part of speech
  • Example usage, when available
  • Etymology, when available

/find-word-for

Finds a single word that best fits a given sentence or prompt.

Option

Name Type Required Description
sentence string yes The sentence or idea to find a word for

The bot asks OpenAI for a single descriptive word, then looks up that word’s definition and etymology through Wordnik.

Environment variables

Create a .env file in the project root.

DISCORD_TOKEN=your-discord-bot-token
GUILD_ID=your-discord-server-id
DISCORD_CHANNEL_ID=your-discord-channel-id

WORDNIK_URL=https://api.wordnik.com/v4
WORDNIK_TOKEN=your-wordnik-api-token

OPENAI_TOKEN=your-openai-api-token

Required variables

Variable Description
DISCORD_TOKEN Discord bot token
GUILD_ID Discord guild/server ID used for command registration
DISCORD_CHANNEL_ID Channel ID used for the scheduled daily word post
WORDNIK_URL Base URL for the Wordnik API
WORDNIK_TOKEN Wordnik API key
OPENAI_TOKEN OpenAI API key used by /find-word-for

Running locally

Install dependencies:

go mod download

Run the bot:

go run ./cmd

The bot will:

  1. Load environment variables from .env
  2. Connect to Discord
  3. Register slash commands for the configured guild
  4. Register interaction handlers
  5. Start the daily word-of-the-day scheduler

Building

Build a binary:

go build -o anglolex ./cmd

Run the binary:

./anglolex

Running with PM2

The repository includes a PM2 config that expects a compiled binary named anglolex.

Build the binary first:

go build -o anglolex ./cmd

Start it with PM2:

pm2 start ecosystem.config.cjs

Scheduled posting

AngloLex schedules a daily Wordnik word-of-the-day post at 10:00 UTC.

The message is posted to the Discord channel configured with DISCORD_CHANNEL_ID.

Project structure

.
├── cmd/
│   └── main.go                  # Application entry point
├── internal/
│   └── discord/
│       ├── bot.go               # Discord session setup
│       ├── commands.go          # Slash command registration
│       ├── handlers.go          # Slash command handlers
│       └── daily-poster.go      # Scheduled word-of-the-day posting
├── pkg/
│   ├── openai/
│   │   └── openapi-service.go   # OpenAI-powered word finder
│   └── wordnik/
│       └── wordnik.service.go   # Wordnik API integration
├── utils/
│   └── xml-converter.go         # Etymology XML formatting
├── ecosystem.config.cjs         # PM2 process config
├── go.mod
├── go.sum
└── README.md

Notes

AngloLex registers commands directly against the configured guild. That is useful during development because guild commands usually appear faster than global Discord application commands.

The /find-word-for command defers its Discord response before calling OpenAI and Wordnik, then edits the response once the lookup is complete.

The current OpenAI prompt asks for a single descriptive word, using GPT-4o with a low temperature for more stable output.

About

Simply retreives the word of the day from [Wordnik](https://developer.wordnik.com/docs#!/words/getWordOfTheDay) and displays it in my discord channel

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages