This repository was archived by the owner on Aug 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
101 lines (82 loc) · 2.78 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
const { Client, Collection } = require("discord.js-selfbot-v13");
const { sendMessage } = require('./utils');
const client = new Client();
const fs = require('fs');
const { promisify } = require('util');
const readdir = promisify(fs.readdir);
let prefix;
const commands = new Collection();
function readData() {
try {
const data = fs.readFileSync('./info.log', 'utf8');
const lines = data.split('\n');
const infoData = {};
lines.forEach(line => {
const [item, value] = line.trim().split(' ');
infoData[item] = value;
});
return infoData;
} catch (err) {
console.error('SawaSB > Error reading info file:', err);
return null;
}
}
function readConfig() {
try {
const configFile = fs.readFileSync('./Config.log', 'utf8');
const lines = configFile.split('\n');
const cfg = {};
lines.forEach(line => {
if (line.trim().startsWith('//') || line.trim().startsWith('--')) {
return;
}
const [key, value] = line.trim().split(/\s+/);
cfg[key] = value;
});
return cfg;
} catch (err) {
console.error('SawaSB > Error reading Config file:', err);
return null;
}
}
async function loadCommands() {
try {
const info = readData();
const config = readConfig();
const commandFiles = await readdir('./commands');
for (const file of commandFiles) {
if (file.endsWith('.js')) {
const command = require(`./commands/${file}`);
commands.set(command.name, command);
}
}
console.log(`${info.Name} > Commands loaded successfully.`);
} catch (error) {
const info = readData();
console.error(`${info.Name} > Error loading commands: ${error}`);
}
}
// On-ready Event
client.on('ready', async () => {
const info = readData();
const config = readConfig();
console.log(`${info.Name} | Client "${client.sessionId}" (${client.user.username}) is ready! | ${info.API} ${info.Version}`);
prefix = config.Prefix;
await loadCommands();
});
// Message Event
client.on('message', async (message) => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).trim().split(/ +/);
const commandName = args.shift().toLowerCase();
const command = commands.get(commandName);
if (!command) return;
try {
await command.execute(message, args);
} catch (error) {
console.error('Error executing command:', error);
message.reply('`SawaSB > There was an error while executing this command.`');
}
});
const config = readConfig();
client.login(`${config.ClientToken}`);