discord-bot-nlp/README.md
2025-07-09 13:03:05 +10:00

75 lines
2.7 KiB
Markdown

I went a little overboard with this bot.
This started off as just a NLP test in a Discord bot however I ended up liking
it so I'm porting some additional ideas into it as well, and might just use this
for my guilds.
## Natural Language Processing
Back before the advent of interactions, I never understood why we were trying to
train users on command prefixes. It made sense to have "!do_a_thing" but it was
also unnatural.
We've long had bots that grep out phrases and act when they're made. There was
nothing stopping us from analyzing every on_message for trigger phrases and
performing actions when conditions are met.
We've already trained users on "Hey Google" and Apple has gone as far as "Siri,
".
This bot does away with commands - prefixes or UI commands.
This bot listens out for being mentioned in a Discord or being DM'd directly.
It leverages spaCy to tokenize and lemmatize the message and attempts to detect
intention from a relatively free form message.
## Cog/Action Separation
I have this issue where I'll write a Discord bot and lose a lot of time porting
over logic and commands, or just losing progress all together.
This bot separates a lot of the logic between performing actions and determining
when to perform actions.
- Cogs are used to detect intention and process messages
- Cogs just run actions
- Actions contain automation logic
This is a leadup into creating an API for managing a Discord server, and might
allow me to convert the bot into supporting OpenTofu if I'm motivated.
## REDIS
I had some issues with the MySQL helper. Latency per request was a little too
high. Those database calls added *just* enough latency to be noticable in the
Discord client, and in a few larger requests it even timed out on the
interaction reply.
REDIS is super quick and way easier to configure.
Long story but I much prefer MariaDB to REDIS for storing application data. In
my K3S clusters I can easily just delegate out table/credentials using the
MariaDB provider, and allow the provider to handle scaling for me.
Unfortunately doing this with REDIS isn't as easy. REDIS isn't designed for this
kind of thing and because of that, you'll probably need to run a REDIS pod
alongside your Bot.
But most bots are likely just docker-compose for fun or whatever. I don't see
this as massively scalable code. And REDIS simplifies the ever loving shit out
of the codes logic.
## Notice on AI
People love to jump up and say "OH BUT THIS IS AI".
Yeah no shit mate.
I use AI to skip searching for things. I get it to help along the way then I
ask it to cleanup code afterwards so that I don't have to waste time coding out
try blocks and shit.
Most of this code was just written out and then processed by AI. So fuck off
about it.
If you're curious; ChatGPT and Gemini.