-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
65 lines (56 loc) · 2.03 KB
/
index.js
File metadata and controls
65 lines (56 loc) · 2.03 KB
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
const Discord = require("discord.js")
const bot = new Discord.Client({ ws: { intents: Discord.Intents.ALL }});
bot.commands = new Discord.Collection();
const botCommands = require('./commands');
const prefix = process.env.prefix
require("./slash")
require("./server")
require("./inlineReply")
const Ping = require("./commands/ping")
const axios = require("axios")
Object.keys(botCommands).map(key => {
bot.commands.set(botCommands[key].name, botCommands[key]);
});
bot.on('message', async (message) => {
const args1 = message.content.slice(prefix.length).trim().split(/ +/);
const commandName1 = args1.shift().toLowerCase();
if (commandName1 === "giveawayslash") {
if (message.author.bot) {
bot.commands.get("giveawayslash").execute(message, args1);
}
}
if (message.author.bot) return;
Ping.test(message);
//if (!message.content.toLowerCase().startsWith(prefix)) return;
const escapeRegex = str => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const prefixRegex = new RegExp(`^(<@!?${bot.user.id}>|${escapeRegex(prefix)})\\s*`);
if (!prefixRegex.test(message.content.toLowerCase())) return;
const [, matchedPrefix] = message.content.toLowerCase().match(prefixRegex);
const args = message.content.slice(matchedPrefix.length).trim().split(/ +/g);
const commandName = args.shift().toLowerCase();
if (!bot.commands.has(commandName)) return;
try {
if (commandName !== "giveawayslash") {
await bot.commands.get(commandName).execute(message, args);
}
} catch (error) {
if (`${error}` === `DiscordAPIError: Cannot send an empty message`) return;
message.channel.send(`An error occured: ${error}`);
}
});
bot.once('ready', async () => {
console.log(`${bot.user.username} main is ready to go!`);
bot.user.setPresence({
activity: {
name: `${prefix}help | JS version of RandomBot`,
},
})
await axios.post(`https://top.gg/api/bots/${bot.user.id}/stats`, {
server_count: bot.guilds.cache.size
}, {
headers: {
"Authorization": process.env.topgg_token
}
})
});
bot.login(process.env.token)