Skip to content

Discord bot to fetch and post the daily Leetcode question

Notifications You must be signed in to change notification settings

reidhaegele/lc-discord-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Leetcode Discord Bot

This Discord bot fetches the daily Leetcode question and posts it in your server's forum.


image
Forum post automatically posted by Leetcode-Daily bot

Usage

  • Create a Discord Developer account

  • Create a new Discord bot

  • Copy bot token (NOT THE SECRET) by hitting "Reset Token" image

  • 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 the createForumPost(); 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 run node 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

About

Discord bot to fetch and post the daily Leetcode question

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published