2024-07-07

·Visit Project

Community Bot

Make community management easier for server admins and mods, regardless of the size of the community. Has REST API & Dashboard.

Table of Contents

What is this bot?

The Discord Community Bot is designed to make community management easier for server admins and mods, regardless of the size of the community.

REST API Usage

The REST API provides information about the commands available in the Discord bot. Here are the details on how to use the API.

Base URL

http://localhost:3000/api/v1

Endpoints

Get Command Details

  • URL: /commands
  • Method: GET
  • Description: Retrieves a list of command categories and the commands within each category.

Fetching API Data

const express = require('express');
const cors = require('cors');
const fs = require('fs');
const path = require('path');

const router = express.Router();

router.use(cors());

// Middleware to log requests
router.use((req, res, next) => {
  console.log(`[${new Date().toISOString()}] ${req.method} ${req.originalUrl}`);
  next();
});

const getCommandDetails = (dir) => {
  const commandDetails = [];
  const commandFolders = fs.readdirSync(dir);

  for (const folder of commandFolders) {
    const commandFiles = fs.readdirSync(path.join(dir, folder)).filter(file => file.endsWith('.js'));
    const commands = commandFiles.map(file => path.basename(file, '.js'));

    if (commands.length > 0) {
      commandDetails.push({
        category: folder,
        commands: commands,
      });
    }
  }
  return commandDetails;
};

router.get('/commands', (req, res) => {
  const commandDetails = getCommandDetails(path.join(__dirname, '../../commands'));
  res.json({ commandDetails });
});

module.exports = router;

Example Request

To get the command details, you can use any HTTP client like curl, Postman, or simply open your browser and navigate to the following URL:

http://localhost:3000/api/v1/commands

Example Response

{
  "commandDetails": [
    {
      "category": "Info",
      "commands": ["help", "uptime"]
    },
    {
      "category": "Moderation",
      "commands": ["kick"]
    }
  ]
}

Example Using Postman

  1. Open Postman.
  2. Create a new GET request.
  3. Enter the request URL: http://localhost:3000/api/v1/commands.
  4. Send the request.
  5. View the response in JSON format, showing the command categories and the commands within each category.

If you disable the REST API in the config.json, the dashboard won't be able to fetch the stats & commands.

Contributing

Contributions to this project are welcome! If you'd like to contribute, please fork the repository and submit a pull request with your changes.

Issues

If you encounter any issues or have suggestions, please open an issue on the GitHub repository.


#Tags

discord
bot
dashboard
nextjs

Contact

Need more project details, have any doubts in mind, or interested in working together? Reach out to me directly at krushnavyas066@gmail.com. I'd be happy to connect and talk!

← All Projects