-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMooMooBot.js
More file actions
69 lines (58 loc) · 2.36 KB
/
MooMooBot.js
File metadata and controls
69 lines (58 loc) · 2.36 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
66
67
68
69
require("dotenv").config();
const Discord = require('discord.js');
const client = new Discord.Client({
intents: [Discord.IntentsBitField.Flags.Guilds, Discord.IntentsBitField.Flags.GuildMessages, Discord.IntentsBitField.Flags.GuildMembers]
});
const fs = require("fs");
const commandFiles = fs.readdirSync("./src/commands").filter(file => file.endsWith(".js"));
const commands = [];
for (const file of commandFiles) {
const CommandClass = require(`./src/commands/${file}`);
const command = new CommandClass(client);
if (!command.example) {
commands.push(command);
}
}
const helpCommand = require(`./src/commands/help`);
const help = new helpCommand(client);
help.loadCommands(commands);
commands.push(help)
require('./src/restApiCall')(process.env.BOT_TOKEN, commands)
client.on("interactionCreate", async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = commands.find(c => c.name === interaction.commandName || c.aliases.includes(interaction.commandName));
if (!command) return;
if (command.userPermissions && interaction.member.permissions.has(...command.userPermissions)) {
let permissions = [...command.userPermissions]
let saveperms = []
interaction.member.permissions.toArray().forEach(permission => {
if(permissions.includes(permission)) {
saveperms.push(permission)
}
})
let hasPermission = permissions.toString() == saveperms.toString()
if(!hasPermission) {
interaction.reply("You dont have permissions to execute this command.");
return;
}
}
if (command.cooldown) {
const timeSinceLastUse = Date.now() - (command.lastUse || 0);
if (timeSinceLastUse < command.cooldown) {
const timeLeft = (command.cooldown - timeSinceLastUse) / 1000;
await interaction.reply(`Please wait ${timeLeft.toFixed(1)} seconds before using this command again.`);
return;
}
}
command.lastUse = Date.now();
try {
await command.execute(interaction, interaction.options.data);
} catch (error) {
console.error(error);
await interaction.reply("An error occurred while executing the command.");
}
});
client.on("ready", function() {
console.log("ready as " + client.user.tag)
})
client.login(process.env.BOT_TOKEN);