-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
92 lines (68 loc) · 2.37 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const fs = require('fs');
const Discord = require("discord.js")
const config = require('./config.json')
require('dotenv').config()
const con = require('./backend.js');
const utils = require('./utils.js');
//require('./api.js')
// var CronJobManager = require('cron-job-manager'),
// manager = new CronJobManager();
const bot = new Discord.Client();
bot.commands = new Discord.Collection();
module.exports = {
bot,
botGuild: (serverId) => {
return bot.guilds.cache.get(serverId)
},
}
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
// Config
const token = process.env.token
const prefix = config.prefix
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
bot.commands.set(command.name, command);
}
bot.on("guildCreate", guild => {
let defaultChannel = "";
guild.channels.cache.forEach((channel) => {
if (channel.type == "text" && defaultChannel == "") {
if (channel.permissionsFor(guild.me).has("SEND_MESSAGES")) {
defaultChannel = channel;
}
}
})
defaultChannel.send('Ola, eu sou seu novo Bot, use `%help` para mais informações.')
});
bot.on("ready", () => {
console.log(`Bot has started, with
${bot.users.cache.size} users, in
${bot.channels.cache.size} channels of
${bot.guilds.cache.size} guilds.`);
bot.user.setActivity(`Serving
${bot.guilds.cache.size} servers :robot:`);
utils.setupSchedules();
//console.log(bot.guilds.cache)
const used = process.memoryUsage().heapUsed / 1024 / 1024;
console.log(`The script uses approximately ${Math.round(used * 100) / 100} MB`);
});
bot.on('message', async msg => {
if (msg.author.bot) return;
if (msg.channel.type === 'dm') {
return msg.reply('Não executo comandos em DM!')
}
if (msg.content.startsWith(prefix)) {
const args = msg.content.slice(prefix.length).trim().split(/ +/)
const commandName = args.shift().toLowerCase()
const command = bot.commands.get(commandName)
if (!command) return
command.execute(msg, args)
//console.log(command)
return
}
let channelId = await con.get(msg.guild.id, "default_channel_id")
if (channelId == null || msg.channel.id == channelId) {
con.addMensageCount(msg.guild.id)
}
})
bot.login(token)