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.
- Go 1.23.3
- DiscordGo
- Wordnik API
- OpenAI API
godotenvfor environment variable loadinggocronfor scheduled daily posting- PM2 support via
ecosystem.config.cjs
- Discord slash command registration
/word-of-the-daycommand/definecommand with definitions and etymology/find-word-forcommand 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
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
Looks up a word using Wordnik.
| 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
Finds a single word that best fits a given sentence or prompt.
| 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.
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| 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 |
Install dependencies:
go mod downloadRun the bot:
go run ./cmdThe bot will:
- Load environment variables from
.env - Connect to Discord
- Register slash commands for the configured guild
- Register interaction handlers
- Start the daily word-of-the-day scheduler
Build a binary:
go build -o anglolex ./cmdRun the binary:
./anglolexThe repository includes a PM2 config that expects a compiled binary named anglolex.
Build the binary first:
go build -o anglolex ./cmdStart it with PM2:
pm2 start ecosystem.config.cjsAngloLex 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.
.
├── 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
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.