GithubHelp home page GithubHelp logo

dixlyn / discord-sticky-message-bot Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andrerahardjo97/discord-sticky-message-bot

0.0 0.0 0.0 121 KB

A simple bot that gonna send your stickied message after few message.

License: GNU General Public License v3.0

JavaScript 96.53% Shell 3.47%

discord-sticky-message-bot's Introduction


Discord Sticky Message Bot


Bot preview

License

About

This bot gonna send your stickied message after few message.
This bot is inspired by StickyBot.

Support

I don't offer support about error in installation. I only offer support for bug and error when the code is running.
I will try to keep the code up to date when there's a major release in libraries that this bot use.

Contributing

I only welcome pull requests that fix bug, typo, or broken english.
If you want to add new feature to this bot, just fork this repository.

Requirements

  • Node.js v14 or higher
  • NPM (Included in Node.js installer by default) or Yarn

If you use NPM, delete yarn.lock file.

Getting Started

  1. Clone or download this repository
  2. Go to the folder where you clone or download this repository
  3. Type npm install or yarn install depend on what you use
  4. Rename .env.example to .env and fill that file. Below is the explanation.
DISCORD_TOKEN=(fill your bot token here)
ALLOWED_ROLES_ID=(allowed roles id, just leave it blank if you don't want to use this)
MAX_MESSAGE_COUNT=(how many message before the bot send the message again. Minimum is 5 if you want to comply with Discord ToS)
OWNER=(your user id or someone user id (e.g. server owner))
PREFIX=(command prefix)
  1. Type node index.js to start the bot

If you don't know how to get the bot token, check this guide.
You want to host it? Check this hosting guide.
If you use Heroku, do not commit the .env file and fill the .env like the guide above said.
After you deploy it on Heroku, if it's your first time, don't forget to turn on all the process type. I already include the Procfile file for Heroku in this repository.

Usage

-stick <message that you want to stick>

-unstick

Code Explanation

This is a Gateway Intents.

const client = new Discord.Client({
  ws: {
    intents: [
      "GUILDS",
      "GUILD_MESSAGES",
    ],
  },
});

I define the Gateway Intents because this bot only use message event. There's no use to listen to other event.

Remove the code below (line 23-25) if you gonna use this bot on a bot channel. The code below make the bot not execute the rest of the code if the sender of the message is bot.

if (message.author.bot) {
  return;
}

The code below only run if the message does not have command prefix.

// Check if the message have command prefix or not.
if (message.content.indexOf(process.env.PREFIX) !== 0) {
  // Check if user already stick a message or not.
  if (stickyMessageContent !== "") {
    // Check the channel id, is it same with the channel id where the message is stickied.
    if (message.channel.id === stickyMessageChannel) {
      // Increment message counter.
      messageCount++;
      // Check if it's already hit the maximum message count that is defined.
      if (messageCount === maxMessageCount) {
        // Delete last sticky message.
        await lastStickyMessage.delete();
        // Send new sticky message.
        lastStickyMessage = await message.channel.send(stickyMessageContent);
        // Reset the counter.
        messageCount = 0;
      }
    }
  }

  return;
}

Split the message by space if the message has command prefix.

const args = message.content.slice(1).trim().split(/ +/g);

Get the first element of args, because it's the command name

const command = args.shift().toLowerCase();

Library That I Use

License

GNU GPLv3

discord-sticky-message-bot's People

Contributors

andrerahardjo97 avatar dependabot[bot] 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.