Skip to content

Instantly share code, notes, and snippets.

@Tylian
Created January 18, 2018 05:21
Show Gist options
  • Save Tylian/f574a5f95ba05e43ae39685404f2067c to your computer and use it in GitHub Desktop.
Save Tylian/f574a5f95ba05e43ae39685404f2067c to your computer and use it in GitHub Desktop.

Installation

  1. Download and install NodeJS.
  2. npm install --no-optional
  3. Make a bot account.
  4. Edit the config, placing the bot token in the config.
  5. Invite the bot to your Discord with a link like https://discordapp.com/api/oauth2/authorize?client_id=CLIENT_ID&scope=bot&permissions=4, replacing CLIENT_ID with the one on the developer page.
  6. Party?
{
"token": "REPLACE ME (see readme)",
"keywords": ["booty", "doodoo", "poopie"]
}
const Eris = require("eris");
const config = require("./config.json");
const regex = new RegExp(`(?:${config["keywords"].map(keyword => keyword.replace(/[-\/\\^$*+?.()|[\]{}]/g, "\\$&")).join("|")})`);
var bot = new Eris(config["token"]);
bot.on("messageCreate", message => {
let match = message.content.match(regex);
if(match && typeof message.channel.guild !== "undefined") {
bot.banGuildMember(message.channel.guild.id, message.author.id, 0, `User said "${match[0]}"`).catch(e => {
console.log(`Failed to ban ${message.author.username}#${message.author.discriminator}. Do I have permission to ban people?\n\n${e.message}`);
});
}
});
bot.connect();
{
"name": "banbot",
"version": "1.0.0",
"description": "A Discord bot that bans when keywords are mentioned.",
"main": "index.js",
"author": "Tylian",
"license": "WTFPL",
"dependencies": {
"eris": "^0.8.2"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment