Giter Club home page Giter Club logo

discord-bot's Introduction

Discord Bot with a REST API

This project was developed for Turing College's Module 3, Sprint 2 at Turing College. This bot is intended to congratulate users that have completed a sprint with a random template message, and a gif. It is designed and implemented with a REST API that interacts with the database, organizing the data across the tables for users, sprints, templates, and messages.

Technologies

  • Backend Framework: Express.js
  • Database Query Builder: Kysely
  • Validation Library: zod
  • Testing Framework: Vitest
  • Programming Language: TypeScript
  • Linting and Formatting: ESLint, Prettier

Prerequisites

Before you begin, ensure you have met the following requirements:

  • You have installed node.js and npm.
  • You have a .env file in your project root with the following environment variables:
DATABASE_URL= Your path to the database
DISCORD_BOT_ID= Your discord bot id
GIPHY_API_KEY= Your Giphy api key
DISCORD_CHANNEL_ID= Your discord channel id

Discord BOT configuration

You have to enable the following inside the Bot page

  • Presence Intent
  • Server Members Intent
  • Message Content Intent

While adding your bot to your server as well, for the url generator you have to also enable Bot inside Scopes and Administrator inside Bot permissions

Migrations & Types

To apply the latest migrations:

npm run migrate:latest

To create a new migration:

npm run migrate:make [migration_name]

To update types

npm run gen:types

Running the server

In development mode:

npm run dev

In production mode:

npm run start

Structure of the database

Messages

{
  messageId: Generated<number>;
  userId: number;
  sprintId: number;
  templateId: number;
  timestamp: string;
  status: string;
}

Sprints

{
  sprintId: Generated<number>;
  sprintCode: string;
  title: string;
}

Templates

{
  templateId: Generated<number>;
  content: string;
}

Users

{
  userId: Generated<number>;
  discordId: string;
}

Using the Bot

Before creating a message you need users, templates, and sprints for it. When those are created, you can use them to post a message. To post a message you should provide the user id with a sprint id, you don't need to give template id it will be random. If you use the discord id of a user instead of their username, then the user will get tagged. Otherwise the user will look like they get tagged, but they won't be notified. The gif that will be inside the message is one of these topics: congratulations, celebration, and success.

Examples

To add a user you have to use the url: http://localhost:3000/users and json body:

{
	"discordId": "Mehmet"
}

To add a sprint you have to use the url: http://localhost:3000/sprints and json body:

{
	"sprintCode": "WD-1-1"
    "title": "Python Beginners"
}

To add a templates you have to use the url: http://localhost:3000/templates and json body:

{
	"content": "Great job!"
}

To add a messages you have to use the url: http://localhost:3000/messages and json body:

{
    "userId": 1,
    "sprintId": 1
}

discord-bot's People

Contributors

mehmettop360 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.