-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.js
73 lines (68 loc) · 2.32 KB
/
main.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
const Discord = require('discord.js');
const fs = require('fs');
const client = new Discord.Client();
const inquirer = require("inquirer");
fs.access("conf.json", async (err) => {
if (err) {
console.log("File doesnt exists. Let's create one.")
await createConfigFile()
console.log("conf.json file successfully created. Restarting in 5 seconds...")
setTimeout(async() => {
await runBot('./conf.json')
}, 5000);
} else {
await runBot('./conf.json')
}
});
async function createConfigFile(params) {
await inquirer.prompt([{
name: "token",
type: "input",
message: "What is your bot token?",
}, {
name: "prefix",
type: "input",
message: "What is your bot prefix?",
default: "!"
}, {
name: "owners",
type: "input",
message: "What are the ids of owners of the bot?(leave a one space between each)",
}]).then((answer) => {
answer.owners = answer.owners.split(" ")
const fileName = "conf.json";
var configDatas = {
token: answer.token,
prefix: answer.prefix,
owners: answer.owners
}
const content = JSON.stringify(configDatas);
fs.writeFileSync(fileName, content);
});
}
async function runBot(configfile) {
const config = require(configfile);
fs.readdir("./events", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
const event = require(`./events/${file}`);
let eventName = file.split(".")[0];
client.on(eventName, event.bind(null, client));
});
});
client.commands = new Discord.Collection();
client.aliases = new Discord.Collection();
client.config = config;
fs.readdir("./commands", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith('.js')) return
let commands = require(`./commands/${file}`);
let commandName = file.split(".")[0];
console.log(`Command Loaded: ${commandName}`);
client.commands.set(commands.config.name, commands);
commands.config.aliases.forEach(alias => client.aliases.set(alias, commandName));
});
});
client.login(config.token);
}