-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
74 lines (66 loc) · 2.13 KB
/
index.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
require("dotenv").config();
const { Collection, GatewayIntentBits, Client } = require("discord.js");
const bot = new Client({ intents: GatewayIntentBits.Guilds });
const fs = require('fs');
const { commandHandler } = require("./src/commandHandler.js");
const { GetData, WriteData } = require("./src/controller/controllerData.js");
const value = require("./src/value.js");
const { embedProfile, FindProfile, checkAuctions} = require("./src/controller/controller.js");
const path = require("path");
bot.commands = new Collection()
bot.commandArray = []
let listeProfiles = GetData("data") //updates profiles
listeProfiles.forEach(player => {
if(player.stats.trades == undefined) {
player.stats["trades"] = {
pokeSold: 0,
pokeBuy: 0,
trades: 0,
}
}
if(player.stats.combats == undefined) {
player.stats["combats"] = {
amical: {
total: 0,
win: 0,
},
raid: {
total: 0,
done: 0,
win: 0,
}
}
}
});
WriteData("data", listeProfiles)
setInterval(() => {//update profiles
if (value.lastProfil != null) {
value.lasMsgProfil.edit(embedProfile(FindProfile(value.lastProfil.id), value.lasMsgProfil.interaction.user.id));
}
checkAuctions(bot)
}, 30000);
bot.on("ready", async () => {
const foldersPath = path.join(__dirname, '/src/commands');
const commandFiles = fs.readdirSync(foldersPath).filter(file => file.endsWith('.js'))
for (const file of commandFiles) {
const filePath = path.join(foldersPath, file);
const command = require(filePath);
bot.commands.set(command.data.name, command);
await bot.application.commands.create(command.data)
}
console.log("bot online");
console.log(new Date().toLocaleString());
});
bot.on("interactionCreate", (interaction) => {
commandHandler(bot, interaction);
});
bot.on("guildMemberUpdate", (oldMember, newMember) => {
let listeProfiles = GetData("data");
for (let i = 0; i < listeProfiles.length; i++) {
if (listeProfiles[i].id == oldMember.id) {
listeProfiles[i].displayName = newMember.displayName;
}
}
WriteData("data", listeProfiles);
});
bot.login(process.env.BOT_TOKEN);