root index legacy

Turing Complete Mentions

A Discord bot that allows for Turing-Complete mentions. Discussing some design decisions and writing about what I learned building it. 2022-01-11

GitHub

The Idea

A few weeks ago, I had the idea to create a way to mention people in a more precise way on Discord. Then, yesterday morning, I figured I would try to build a bot that would do just that.

Turing Complete Mentions is a bot that uses JavaScript to create complex criteria for mentions. This way, only the people you want mentioned are actually mentioned.

Here are some screenshots of some real-world use cases of this bot:

mentioning everyone with no roles mentioning currently active moderators

How it Works

The way this bot works is pretty simple. After a message is received and a mention is detected using a RegExp, the bot will use a JavaScript Function to create a private scope to run the criteria over every server member. This way, the JavaScript code is executed in a sandboxed environment and ensures optimal performance on the V8 engine, which NodeJS is based on.

A key set of arguments from the Discord API are passed to the function automatically (namely server, member, user, status, activities and roles), which you can read more about on the project's GitHub. These arguments constitute the interface available to the JavaScript criteria code, which you can then use when mentioning members on a Discord server.

Initially, the bot would add a special role to the right members of a server and only mention this one role. However, because of the rate limit Discord imposes on all requests, the bot was limited to adding less than 2 roles per second. This is an obvious issue, as it would take a good few minutes to mention all members of a reasonably large server. To work around this limitation, the bot now mentions all members individually through a 2000-character buffered reply. This way, it can mention any number of members with practically no delay, which is essential given the fact that this bot is most useful in large servers.

Adding This Bot to Your Server

If all of that sounds interesting, you can click here to invite Discord Assistant to one of your servers. However, if you wish to host the bot yourself to have complete control over its functionality, you should take a look at the README.md in the project's GitHub.

What I Learned

Before starting this project, I had already built a Discord bot using JavaScript and NodeJS, which you can learn more about here. With that said, I still learned a lot about the Discord API and about how to deal with Discord's rate limit imposed on adding and removing server roles. I am currently using Turing Complete Mentions in the servers I set up for some of the classes I have at uOttawa, and it proves to be a great tool for those who want to mention people in a more precise way.