
Ask HN: How would you design a scalable chat bot for something like Discord? - iDemonix
I have 2 months of furlough, and I&#x27;d like to improve my Python (and other) skills and, for once, start and finish a project. For once I&#x27;ve decided to pick a project which will actually both interest and benefit myself.<p>I wrote a simple chat bot to manage xp&#x2F;levels&#x2F;roles, amongst various other things, in  a Discord server for a popular community. I&#x27;ve since used the same bot in other communities, but it just runs as a clone of a Python repo for each bot, using supervisord on a Digital Ocean VPS. Each bot also has its own developer &#x27;app&#x27; within the Discord environment and associated tokens, which is getting cumbersome to manage.<p>As I&#x27;ve got time to focus on it, I&#x27;d like to create a singular bot, with a web UI to manage it, with a very long term end goal of maybe competing with other services like Mee6, but a shorter term goal of making it easy for me to easily add the bot to new communities and configure it - without config + manual steps over SSH.<p>It&#x27;s quite niche, but if anyone has any similar experience, I&#x27;d be eager to hear any opinions. For example: My first instinct based upon my work experience was a Docker container per bot, but from testing, as far as I can see I need a single instance which handles all servers if I want to use one developer &#x27;app&#x27; like Mee6 or Dyno.<p>Any hints&#x2F;links or similar welcome.
======
caryd
Docker alone would not add automatic scalability. You'd need to add an
orchestration layer.

Seems like your current bot would be fine in multiple servers if you added an
additional server argument to each of the i/o's.

Don't overthink it.

~~~
iDemonix
Yeah I have some projects at work which manage containers in this kind of
fashion, which is probably why I'm applying that to this and over-engineering
- which I almost always do.

The current bot could work with just passing in a token, and then fetching its
settings from a REST API (for the web bit) instead of just a JSON file - my
only issue with this approach is I think it'd require the user to setup a
developer app with discord user, instead of the nice seamless 'invite and it
works' approach other bots seem to have.

------
curryst
You can certainly run more than one Discord server on a single running
instance of the bot. That's probably more code, but you could run the web
server as part of the same process. I would generally discourage that though,
because then you can have your bots DDoSed by just DDoSing your web server.

The easier incarnation is to store the Discord connection configs in a
database. Make a web server and UI to manage the database (the Django admin
panel is probably enough, which would make it low code). Then have the web
server manage an orchestration layer by pulling configs from the database. The
easy solution is probably to have your web server write out supervisord config
files templated from the data in the database, and then send reload signals to
supervisord. The more difficult option there would be to write your own
process management layer (probably not worth it, you're just rewriting
supervisord at that point). Or you could maybe just pull in supervisord as a
library and use it.

That solution is less resource efficient, but not at a "break the bank" level.

~~~
iDemonix
Thanks, you've described what I had in my head as a rough way of doing things
- the issue with this approach is that it appears to be one bot instance per
user. I.e. if I want the same 'user' to be able to be invited to unlimited
servers, that 'user' must run from a single application instance - meaning all
server chats flow through a single app instance.

------
drzel
I have a discord bot running in our FortressOne discord. It keeps track of who
is in what server and spams the channel with that information. It requires
some short term persistence so it runs across two containers, one with the
application code and the other with redis. It takes hundreds of requests daily
and sends many millions, seems to be very stable.
[https://github.com/FortressOne/qwtf-discord-
bot](https://github.com/FortressOne/qwtf-discord-bot)

------
based2
[https://docs.mattermost.com/overview/product.html#about-
the-...](https://docs.mattermost.com/overview/product.html#about-the-
mattermost-open-source-project)

[https://github.com/42wim/matterbridge](https://github.com/42wim/matterbridge)

[https://git.koesters.xyz/timo/conduit](https://git.koesters.xyz/timo/conduit)

[https://matrix.org/docs/guides/introduction](https://matrix.org/docs/guides/introduction)

------
Axsuul
Why did you clone in the beginning? Why couldn't you have just on developer
app send requests from multiple communities to one endpoint for your app?

~~~
iDemonix
I don't know how well that would scale though with multiple popular servers.

~~~
Axsuul
It can scale well since you can use a load balancer if traffic gets too much
for one server.

------
babuloseo
In the discussion of Discord Bots, be aware of Discord Bots that share your
private group channel data online.

