Learn-Build-Teach / learn-build-teach-discord-bot

53 stars 17 forks source link
hacktoberfest hacktoberfest2021

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.

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

# api
SERVER_API_KEY=

# discord
DISCORD_BOT_TOKEN=
DISCORD_GUILD_ID=
DISCORD_CLIENT_ID=

# supabase
SUPABASE_SERVICE_ROLE_KEY=
SUPABASE_PROJECT_URL=

Optional Variables


#Discord
DISCORD_GENERAL_VOICE_ID=<GENERAL_VOICE_ID>
ALLOW_SELF_KUDOS=<TRUE|FALSE>
ENABLE_EVENTS_SCHEDULER=<TRUE|FALSE>
EVENT_SCHEDULER_CRON=<CRON SYNTAX>
DISCORD_DISCUSSIONS_CHANNEL_ID=<DISCUSSSIONS_CHANNEL_ID>
POST_WEEKLY_DISCUSSION_QUESTION=<TRUE|FALSE>

#Api - used for authentication on API requests
SERVER_API_KEY=<API_KEY>

#Email alerts - used to send email alerts based on errors
EMAIL_ALERTS_ON=<TRUE|FALSE>
EMAIL_ALERTS_RECIPIENT=<EMAIL@EMAIL.COM>
EMAIL_ALERTS_SENDER=<EMAIL@EMAIL.COM>
SENDGRID_API_KEY=<API_KEY>

#Twitter - used for sending automatic tweets of content
SEND_TWEETS=<TRUE|FALSE>
TWITTER_ACCESS_TOKEN_KEY=<ACCESS_TOKEN_KEY>
TWITTER_ACCESS_TOKEN_SECRET=<ACCESS_TOKEN_SECRET>
TWITTER_CONSUMER_KEY=<CONSUMER_KEY>
TWITTER_CONSUMER_SECRET=<CONSUMER_KEY>

#Discord Admin - used for reviewing shared content
DISCORD_ADMIN_SHARE_REVIEW_CHANNEL=<REVIEW_CHANNEL_ID>

#Highlight
HIGHLIGHT_PROJECT_ID=<YOUR_PROJECT_ID>

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.

/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.