-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c9c71e
commit 08102d9
Showing
4 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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" | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"prefix": "!", | ||
"token": "setmeplease" | ||
} |
This file contains 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
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) |
This file contains 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
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" | ||
} | ||
} |