This Discord bot fetches the daily Leetcode question and posts it in your server's forum.
Forum post automatically posted by Leetcode-Daily bot
-
Create a Discord Developer account
-
Create a new Discord bot
-
Go to OAuth and select applications.commands and bot roles
-
Copy and paste link into browser to invite your bot to your server
-
Ensure your Discord server is a community server with a forum channel created
-
Clone this repo using
git clone
-
Create a
config.json
file with the following (Replace anything in UPPERCASE):
{
"token": "YOUR_TOKEN",
"channels": {
"CHANNE_LNAME": "THE NUMBERS FROM COPYING CHANNEL ID",
"OPTIONAL_2ND_CHANNEL_NAME": "THE NUMBERS FROM COPYING CHANNEL ID"
},
"leetcodeEndpoint": "https://leetcode.com/graphql",
"dailyQuery": "query questionOfToday {activeDailyCodingChallengeQuestion {date userStatus link question { acRate difficulty freqBar frontendQuestionId: questionFrontendId isFavor paidOnly: isPaidOnly status title titleSlug hasVideoSolution hasSolution topicTags {name id slug}}}}"
}
- If testing by running locally, comment out the cron job at the end of
index.js
and uncomment thecreateForumPost();
function call. This will instantly create the forum post rather than schedule it. - To run locally, open your terminal and navigate to the directory where you cloned this repo. Ensure that you have NodeJS installed. Run
npm i
, then runnode index.js
. Check your Discord server to see if the post appeared. - To run it in Google Cloud with scheduled jobs, see the following:
- The cron.schedule line near the end of the
index.js
file controls what time the post is scheduled for daily. Edit this using the cron format. - Install Google Cloud CLI
- Run
gcloud init
- Run
gcloud app deploy