Skip to content

Instantly share code, notes, and snippets.

@bmansk8
Last active December 2, 2019 17:35
Show Gist options
  • Save bmansk8/09d2c1aa364f9db8ca79a077d6c32a02 to your computer and use it in GitHub Desktop.
Save bmansk8/09d2c1aa364f9db8ca79a077d6c32a02 to your computer and use it in GitHub Desktop.
A simple discord bot.
//if you use vs code
//node . starts app
//ctrl c closes bot
//ctrl ` opens console
//make sure to install node
var configObj = {
quotes: [
"put",
"your",
"quotes",
"here"
],
commandsTxt: `my commands are ?ping ?hello ?info ?help ?rules ?quote ?lenny`,
info: `
INFO: your info here
`,
rules: `
RULES:
your rules here
`
};
var quotes = configObj.quotes;
const Discord = require("discord.js");
const client = new Discord.Client();
const token = "your token here";
client.login(token);
client.on("ready", () => {
console.log("I have become self aware!!");
client.user.setActivity("memes", { type: "WATCHING" });
});
//gets a random quote from configObj
function getRandomQuote() {
return quotes[Math.floor(Math.random() * quotes.length)];
}
// Create an event listener for new guild members
client.on("guildMemberAdd", member => {
// Send the message to a designated channel on a server:
const channel = member.guild.channels.find(ch => ch.name === "member-log");
// Do nothing if the channel wasn't found on this server
if (!channel) return;
// Send the message, mentioning the member
channel.send(`Welcome to the server, ${member}`);
});
client.on("message", msg => {
//lenny face command
if(msg.content === '?lenny'){
msg.channel.send('( ͡° ͜ʖ ͡°)');
}
//random quote machine
if (msg.content === "?quote") {
msg.reply(getRandomQuote());
}
//simple ping pong joke
if (msg.content === "?ping") {
msg.reply("Pong!");
}
if (msg.content === "?hello") {
//if someone says hello
let nmbr = Math.floor(Math.random() * Math.floor(3));
//pick random number
//for each number there is a response
switch (nmbr) {
case 0:
msg.reply("hello human!");
break;
case 1:
msg.reply("greetings!");
break;
case 2:
msg.reply("You peasant, hello...");
break;
}
}
if (msg.content === "?rules") {
msg.reply(configObj.rules);
}
if (msg.content === "?info") {
msg.reply(configObj.info);
}
if (msg.content === "?help") {
msg.reply(configObj.commandsTxt);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment