/my-version-

Primary LanguageTypeScript

Learn Build Teach Discord Bot

This bot allows Learn Build Teach Discord members to share content, give kudos to other members, etc.

For a quick a overview of how to create a Discord Bot with Node.js here are a few resources.

Code overview

Commands

Individual commands have their own file inside of the /src/commands directory. Each command should export an object with three properties.

  • callback - a callback function that is triggered when the command is used
  • name - the name of the command
  • description - short description of what the command does

The callback function accepts one parameter which is a Command Interaction. Check out Creating Slash Commands Documentation for more info.

Here is an example.

const resetProfile = async (interaction: CommandInteraction) => {
  //some logic
};
export default {
  callback: resetProfile,
  name: 'resetprofile',
  description: 'Reset your profile settings',
};

Server

The backend is a Node.js and Express app. This is used to handle API requests that are deteailed in the /src/server/routes directory.

Utils

These are utility files for interacting with Discord, Supabase, Twitter, etc.

How to run

1) Install dependencies

npm install

2) Get the API keys/credentials

You can get the API keys from the following websites

3) Set the environment variables

In a .env file, make sure to include the requied environment variables listed below.

You will need to create your own test server in Discord as well as a project in Supabase. We are thinking through easier ways to help with this process if you have ideas.

Required Varaiables

#Supabase
SUPABASE_SERVICE_ROLE_KEY=
SUPABASE_PROJECT_URL=

#Discord
DISCORD_BOT_TOKEN=
DISCORD_GUILD_ID=

Optional Variables

#Api - used for authentication on API requests
SERVER_API_KEY=

#Email alerts - used to send email alerts based on errors
EMAIL_ALERTS_ON=
EMAIL_ALERTS_RECIPIENT=
EMAIL_ALERTS_SENDER=
SENDGRID_API_KEY=

#Twitter - used for sending automatic tweets of content
SEND_TWEETS=
TWITTER_ACCESS_TOKEN_KEY=
TWITTER_ACCESS_TOKEN_SECRET=
TWITTER_CONSUMER_KEY=
TWITTER_CONSUMER_SECRET=

#Discord Admin - used for reviewing shared content
DISCORD_ADMIN_SHARE_REVIEW_CHANNEL= #(optional)

4) Run the bot

npm run dev

Commands

/profile

Get profile details about you or another discord member.

/updateProfile

Update your profile with the following flags. I will use these pieces of information to help share your content.

  • twitter: your Twitter handle
  • twitch: your Twitch username
  • youtube: your YouTube URL
  • instagram: your Instagram username
  • github: your Github username
  • website: your personal website URL

/resetProfile

Clear your existing profile in case your display name has changed, you entered incorrect info, etc.

/share

Share a piece of content (article, video, etc.) by including a valid URL. These pieces of content will considered for sharing on Twitter and/or the James Q Quick newsletter. You can (optionally) include a suggested tweet text after the URL.

ex. /share https://www.jamesqquick.com/ This is a suggested tweet text

/kudo

Give Kudos to another user. Kudos will be automatically given when reacting to a post using the following emojis: 'learn', 'build', and 'teach'.

/kudosLeaderboard

View the Kudos Leaderboard.