This is a Discord bot which posts a "Brainteaser of the Day" to subscribed channels. Users can submit new brainteasers by sending a DM to the bot, and participants are awarded points for actions in the main channel such as submitting solutions and pointing out mistakes in posted solutions.
In a channel, use /subscribe
to subscribe to the Brainteaser of the Day. The bot will then post a brainteaser in that channel every day. The brainteasers are drawn from a database of brainteasers that is initially seeded with 28 brainteasers, but you can add brainteasers to the database by sending a DM to the bot. If there is no brainteaser in the database, the bot will just post an error message.
Note: Populating the database with good brainteasers takes time, but this setup ensures that the brainteasers are of good quality and around the level of difficulty that you are looking for.
There are some additional commands, such as /get_leaderboard
, which shows the current leaderboard of users and their points.
This is not a public bot, so you need to run your own instance of the bot. To set it up, you need the following:
- A Discord account.
- An OpenAI account and API key.
- A machine with Node.js to run the main process (e. g. your local machine or a cloud server).
- A PostgreSQL database (can be on the same machine as the bot or on a remote server).
Personally, I use Heroku to host the bot and database. The file Procfile
in the root directory is my Heroku configuration.
To set up the bot, follow these steps:
- Set up your OpenAI account and PostgreSQL database.
- Set up a new Discord application and bot. Give the bot the username "Brian T. Serbot" and enable Message Content Intent under Priviliged Gateway Intents.
- Clone this repository and setup the
.env
file in the root directory with the following variables:OPENAI_API_KEY
: Your OpenAI API key.DATABASE_URL
: The URL of your PostgreSQL database.DISCORD_APP_ID
: The ID of your Discord application, which can be found in the developer portal.DISCORD_TOKEN
: The token of your Discord bot, which can also be found in the developer portal.DISCORD_PUBLIC_KEY
: The public key of your Discord application, which can also be found in the developer portal.NODE_ENV
: Optional. Set todevelopment
if you do not want to use an SSL connection to the database. I use this to distinguish between local development and deployment on Heroku.
- Run
npm install
andnpm run db:seed
in the root directory to install the dependencies and set up the initial tables in the database. - Run
npm run start
in the root directory to start the bot.
The bot uses the node-schedule package to schedule tasks. These tasks are defined in the src/discord_interface.ts
file, and you can change the schedule by editing the calls to scheduleJob
within this file.