/discord-accountant

Primary LanguageTypeScriptMIT LicenseMIT

Discord Accountant Bot

The Accountant manages Points in Discord servers. In the Eco Discord, Points are "for research purposes only," as we often say — but they have become the lifeblood of our community. We grant Points to members, and then anyone can send those Points to each other. They’ve become an incredible, vibrant transactional layer. Points can represent anything you and your community want them to — a reward, a thank you, a reputation layer, a place in line... anything that can be represented by a number.

(Note: We’ve intentionally added friction to getting into the Eco community, but here’s a hint: having everyone’s favorite 🦊 unlocks a different signup flow on our site. Or you can just answer the riddle correctly. Or there might be other ways to get in, too...)

Options for using The Accountant

There are two ways to use The Accountant:

  1. Deploy The Accountant into your own server, with your own Points, separate from Eco Points. If you do this, you'll be able to grant Points freely — as many as you want. But they won't have any link to Eco Points. To do this, follow the instructions lower in this README under "Set up your own Accountant."

  2. Perhaps even cooler: invite The Accountant into your server using Eco Points. If you do this, members of the Eco Discord can (and will) come over and already have Points in your server. And you can request grants of Eco Points from the Eco community for you to re-distribute to your own community. The Points will persist across every server that has invited The Accountant.

To request grants of Eco Points to distribute to your community, hop into this Discord channel and introduce yourself. You'll need to apply and be approved by the Eco Community.

Being a part of the Eco network is powerful. We're building a coalition of projects, all allowing the same Points to move across different servers and serve as a pro-social transactional layer. We’ll have embassies between different Discord communities, cross-community collaboration, and more.

Here’s a brief explanation about why we’re giving away Points to other communities in the first place.

If you’re even vaguely interested in the idea of adding Eco Points to your server, getting grants of Points, and enabling that cross-community interaction and transaction layer, here’s a link to join a Discord channel where you can chat with us (and we can give you access to the rest of the Eco Discord). We’d love to discuss.

Again, here’s the link to add The Accountant to your server and use Eco Points.

For more

For more about The Accountant Bot and all the rest of the bots open-sourced by the Eco Community, check out this post. There's a member management dashboard, a bot to manage role assignment based on invite links, bots that let you stake and enter sweepstakes with points, and much more.

Set up your own Accountant

  1. Create a MySQL database for the bot. Inside the mysql command line client:
CREATE DATABASE accountant;
  1. Select the database and generate the tables using the db.sql file:
USE accountant
source db.sql
  1. Rename the .env.sample file in the root folder to .env and fill it with your bot token and database details.

  2. To add the bot to servers, go to the Discord Developer Portal, open your bot, click on OAuth2 > URL Generator in the sidebar, enable the bot scope, enable the Send Messages and Manage Messages permissions, then use the generated URL.

    The Manage Messages permission is required for deleting commands that were used in the wrong channel.

    After that you can click on Bot in the sidebar, and enable Public Bot if you want to allow anyone to add the bot to their own servers.

  3. In your Discord server, create four channels; one named #check-your-points for users to check their points, one named #points-log for logging all point transactions from all servers, one named #grants-log for logging grants only, and one named #eco-server-points-log for logging transfers made inside your server only. These names can be customized by editing constants.ts.

  4. Create an emoji for displaying point amounts.

  5. (Optionally) create roles for point milestones (e.g. "0-50 points", "50-250 points")

  6. (Optionally) create a Slack webhook for logging grants: https://api.slack.com/messaging/webhooks

  7. Rename the config_sample.ts file in the src folder to config.ts then use the ID of your server in MAIN_GUILD and fill the rest using the IDs of the emote and roles as well as the Slack webhook created in steps 5, 6 and 7.

  8. Install dependencies:

npm install
  1. Compile TypeScript:
npm run build
  1. And finally, run the bot:
npm run start

Testing locally

Do the setup instructions above, then create a test database using steps 1 and 2, and add its name to .env:

DB_DATABASE_TEST="test_db_name"

Use this command to run the tests:

npm run test

Command Usage

The bot offers the following commands for your users. The admin commands are only available if you are hosting your own deployment of the bot.

Input is specified with <value>. Do not include the < > when executing the command. Make sure to include your chosen prefix before the command (the default is !.)

User Commands

  • help - Returns a list of commands which can be used.
  • leaderboard <number> - Returns a list of the top point holders. It has a maximum of 25. No input will default to 10.
  • ping - Returns the time it took the bot to respond to a request.
  • points <@user> - Returns the amount of points the chosen user has. If no user is mentioned, it will return the points of the message sender.
  • send <@user> <number> - Sends the mentioned users the specified amount of points. Multiple users can be specified before the number of points.

Admin Commands

  • admin add <@user> - Adds a user as an admin.
  • admin remove <@user> - Removes admin privieleges from a user.
  • admin list - Provides a list of current admins.
  • admin stats - Returns the amount of points and grants distributed to users.
  • grant <@user> <number> - Grants the mentioned users the specified amount of points. Multiple users can be specified before the number of points.

Questions? Need help?

Hop into this Discord channel and introduce yourself and we can help out (and give you access to the rest of the Eco Discord).