Git Product home page Git Product logo

discord-bot's Introduction

Self-hosted discord bot

Contents

Installation

Docker

  1. Clone the repository

  2. Install Docker

  3. Install Docker Compose

  4. Create file named .env in the root directory of the project

  5. Paste the following code to the .env file

    TOKEN=
    CLIENT_ID=
    GOOGLE_API=
    MONGODB_URI=
    DB_NAME=<database name>
    1. Create name for the database and replace <database name> with it at DB_NAME
  6. Create an account on MongoDB Atlas

    1. Follow MongoDB Atlas Getting Started
    2. Copy the connection string for Node.js 4.1 or later and paste it to MONGO_URI in .env file
    3. Remember to replace <password> with the password you created for the user in the connection string
  7. Create discord application and bot

    1. Create application
      1. Click New Application in the upper right corner
      2. Enter a name for your app, then click Create.
    2. Create bot
      1. On the left hand sidebar click Bot, then the Add Bot button
      2. Update the username and icon for your bot
      3. Press Reset Token button to generate a new token
    3. Copy the bot token and paste it to TOKEN in .env file
    4. Navigate to the General Information page
      1. Copy the application id and paste it to CLIENT_ID in .env file
    5. Create API Key to Google Custom Search Engine
    6. Copy the API key and paste it to GOOGLE_API in .env file
  8. Invite the bot to your server

    1. Navigate to the OAuth2 page
    2. Select bot from the scopes
    3. Select the permissions you want to give the bot
    4. Copy the generated link and open it in your browser
    5. Select the server you want to add the bot to
    6. Click Authorize
  9. Configure presence of the bot

    1. Open json/config.json file
    2. There you can change bot's Activity status and message
    3. Activity status: online, idle, dnd (do not disturb), invisible
    4. To change bot's Activity type open events/ready.js file
      1. In line 9 you can change the type of the Activity example ActivityType.Playing to ActivityType.Watching
      2. Activity types are: Playing, Streaming, Listening, Watching, Competing
  10. To start the bot run the following command in the root directory of the project

docker compose up -d --no-deps --build

Usage

  1. To restart the bot run the following command in the root directory of the project
docker compose up -d --no-deps --build
  1. To stop the bot run the following command in the root directory of the project
docker compose down
  1. To add new commands

    1. Create new file in commands directory
    2. Copy the following code to the file
    const { EmbedBuilder, ApplicationCommandType } = require('discord.js');
    module.exports = {
       name: '',
       description: "",
       type: ApplicationCommandType.ChatInput,
       
    
    
       run: async (client, interaction) => {
    
       }
    
    };
    1. Replace name with the name of the command
    2. Replace description with the description of the command
    3. Add options if you want to under type
    options: [
         {
             name: '',
             description: '',
             required: true or false,
         }
     ],
    1. Put the code you want to execute when the command is called in the run function

      Discord.js documentation

      Discord.js Guide

    2. Save the file

    3. Restart the bot to apply the changes (see Usage step 1)

discord-bot's People

Contributors

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