This bot gonna send your stickied message after few message.
This bot is inspired by StickyBot.
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.
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.
If you use NPM, delete yarn.lock
file.
- Clone or download this repository
- Go to the folder where you clone or download this repository
- Type
npm install
oryarn install
depend on what you use - 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)
- 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.
-stick <message that you want to stick>
-unstick
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();
- Discord.js
- dotenv
- ESLint (dev dependency)