-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
86 lines (66 loc) · 2.06 KB
/
bot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const Discord = require('discord.js');
const fs = require('fs');
const client = new Discord.Client({ partials: ['MESSAGE', 'CHANNEL', 'REACTION'] });
const PREFIX = "!";
const CONFIG = require("./config.json");
client.commands = new Map();
client.on('ready', () =>
{
console.info(`Logged in as ${client.user.tag}!`);
client.user.setActivity('Hello.', { type: 'PLAYING' });
fs.readdir('./commands/', (error, files) =>
{
if (error) throw error;
files.forEach(file =>
{
if (!file.endsWith('.js')) return;
try
{
const properties = require(`./commands/${file}`);
properties.help.aliases.forEach(alias =>
{
client.commands.set(alias, properties);
});
client.commands.set(properties.help.name, properties);
}
catch (error)
{
throw error;
}
});
});
});
client.on('message', message =>
{
const embed = new Discord.MessageEmbed()
.setAuthor("")
.setColor("#32CD32");
if (message.content[0] != PREFIX) return;
var args = message.content.substring(1).split(" ");
// `Cmd` definition
var cmd = args.shift();
var joinedArgs = restArguments(args, 0);
const command = client.commands.get(cmd);
if (command) command.run(client, message, cmd, args);
if (!command)
{
embed.setDescription(`
The command: \`${PREFIX}${cmd}\` is not recognised.
The prefix for this server is: \`${PREFIX}\`
For a list of commands, use \`${PREFIX}\`help`
);
return message.channel.send(embed);
}
});
/**
* Returns concatted arguments from specific (`0 based`) index (to another)
*
* @param {String[]} args
* @param {number} from
* @param {number} to
* @returns {String} Concatted arguments
*/
function restArguments(args, from, to)
{
return to == undefined ? args.splice(from, args.length).join(" ") : args.splice(from, to - from).join(" ");
}