Skip to content

Instantly share code, notes, and snippets.

@Coocla33
Last active April 14, 2017 12:34
Show Gist options
  • Save Coocla33/946047c699a1ccc781f031e384f35cb2 to your computer and use it in GitHub Desktop.
Save Coocla33/946047c699a1ccc781f031e384f35cb2 to your computer and use it in GitHub Desktop.
{
"token": "Your Token Here",
"prefix": "!"
}
//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