Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
The-SourceCode authored Jun 22, 2018
1 parent 7c9c71e commit 08102d9
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
12 changes: 12 additions & 0 deletions commands/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const Discord = require('discord.js')

module.exports.run = async (bot, message, args) => {
//this is where the actual code for the command goes
await message.delete()
if(message.author.id !== "178657593030475776") return;
return message.reply("Hi! I'm an example command").then(m => m.delete(10000))
}
//name this whatever the command name is.
module.exports.help = {
name: "example"
}
4 changes: 4 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"prefix": "!",
"token": "setmeplease"
}
47 changes: 47 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const Discord = require("discord.js")
const config = require("./config.json")
const bot = new Discord.Client();
const fs = require("fs");
bot.commands = new Discord.Collection();
if(config.token === "setmeplease") return console.log("Set your token up! Go to https://www.discordapp.com/developers and generate a token from a bot user.");

fs.readdir("./commands/", (err, files) => {

if(err) console.log(err);

let jsfile = files.filter(f => f.split(".").pop() === "js");
if(jsfile.length <= 0){
console.log("Couldn't find commands.");
return;
}

jsfile.forEach((f, i) =>{
let props = require(`./commands/${f}`);
console.log(`${f} loaded!`);
bot.commands.set(props.help.name, props);
});

});


bot.on("ready", () => {
console.log(bot.user.username + " is online.")
});

bot.on("message", async message => {
//a little bit of data parsing/general checks
if(message.author.bot) return;
if(message.channel.type === 'dm') return;
let content = message.content.split(" ");
let command = content[0];
let args = text.slice(1);
let prefix = config.prefix;


//checks if message contains a command and runs it
let commandfile = bot.commands.get(command.slice(prefix.length));
if(commandfile) commandfile.run(bot,message,args);
})


bot.login(config.token)
16 changes: 16 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "discordjs_template",
"version": "1.0.0",
"description": "A template for Discordjs with command handler and example file.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Ned from {TheSourceCode}",
"license": "ISC",
"dependencies": {
"discord.js": "^11.3.2",
"fs": "0.0.1-security",
"ms": "^2.1.1"
}
}

0 comments on commit 08102d9

Please sign in to comment.