Last active
April 14, 2017 12:34
-
-
Save Coocla33/946047c699a1ccc781f031e384f35cb2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"token": "Your Token Here", | |
"prefix": "!" | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Require Discord.js | |
const Discord = require('discord.js') | |
//Require config.json | |
const config = require('./config.json') | |
//Create a new bot Account | |
const bot = new Discord.Client() | |
//Create a variable called responseObject containing responses for certain commands. | |
const responseObject = { | |
'ayy': 'Lmao!', | |
'coocla': 'Is the best person ever!', | |
'potato': 'Tomato' | |
} | |
//Logging in with the bot Account using the config.json files | |
bot.login(config.token) | |
//When the bot is read, send a message to the console saying the bot is ready | |
bot.on('ready', () => { | |
console.log('Bot is ready!') | |
}) | |
//Whenever the bot detects a new message, this code will be ran | |
bot.on('message', (message) => { | |
//Check if the content of the message objects starts with config.prefix | |
if (message.content.startsWith(config.prefix)) { | |
//Remove the prefix from the message content | |
//Split it at every space and take the first word | |
//Change the first word to lower case | |
const command = message.content.substr(config.prefix.length).split(' ')[0].toLowerCase() | |
//If the command variable is uqual to ping, succeed. | |
if (command == 'ping') { | |
//Send message containing the following text: Pong! | |
message.channel.sendMessage('Pong!') | |
} | |
if (responseObject[command]) { | |
message.channel.sendMessage(responseObject[command]) | |
} | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment