Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Discord = require('discord.js')
- var client = new Discord.Client()
- var cmds = {}
- var errorlvl
- var prefix = '!'
- function weAreReady() {
- console.log('The bot has successfully logged in.')
- }
- function addCmd(name, argNumber, cmd, usage) {
- cmds[name] = {name:name,func: cmd, usage: usage,argNum: argNumber}
- }
- client.on('ready', weAreReady)
- client.on('message', function (message) {
- if (message.content.startsWith(prefix)) {
- cmd = message.content.split(prefix).pop()
- actualcmd = cmd.split('_').pop()
- var args
- if (cmds[actualcmd] == undefined) {
- //It is not a vailid command
- console.log('invalid cmd')
- console.log('cmd: ' + actualcmd)
- } else {
- //Get to actually parsing the command
- args = cmd.split(cmd).pop().split('_')
- console.log(args)
- console.log(cmds[actualcmd].argNum)
- if (args.length === cmds[actualcmd].argNum + 1) {
- //Correct number of args
- args.unshift(message);
- cmds[actualcmd].func.apply(this, args)
- } else {
- cmds[actualcmd].usage(message)
- }
- }
- }
- })
- addCmd('hello', 0, function (message) {
- message.channel.send('Hello, ' + message.author.username)
- errorlvl = 0
- }, function (message) {
- errorlvl = 1
- message.channel.send(message.author.username + ', the arguments are not complete. The full usage of this command is: !hello')
- })
- client.login('MzE4ODk2MDM5NDM4NDUwNjk5.DA5Cuw.EyshBBnXnrETKf2KPU-MKclulpg')
Advertisement
Add Comment
Please, Sign In to add comment