-
-
Notifications
You must be signed in to change notification settings - Fork 274
/
Copy pathindex.js
85 lines (77 loc) · 2.49 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
require('dotenv').config();
const { Client, GatewayIntentBits, Collection, Partials, EmbedBuilder } = require('discord.js');
const fs = require('fs');
const mongoose = require('mongoose');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildModeration,
],
partials: [Partials.Message, Partials.Channel, Partials.GuildMember],
});
client.commands = new Collection();
// Load commands
const ds = './commands';
fs.readdirSync(ds).forEach(dir => {
const commandFiles = fs.readdirSync(`${ds}/${dir}`).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`${ds}/${dir}/${file}`);
if (command.data && command.execute) {
client.commands.set(command.data.name, command);
}
}
});
//status event
client.once('ready', () => {
console.log(`🤖 Automod Bot ready as ${client.user.tag}`);
client.user.setPresence({
activities: [{ name: 'your server 👀', type: 3 }],
status: 'online'
});
});
// Slash command handler
client.on('interactionCreate', async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) return;
try {
await command.execute(interaction, client);
} catch (error) {
console.error(`Error executing command ${interaction.commandName}:`, error);
const errorEmbed = new EmbedBuilder()
.setTitle('❌ Command Error')
.setDescription('There was an error executing this command.')
.setColor('Red');
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ embeds: [errorEmbed], ephemeral: true });
} else {
await interaction.reply({ embeds: [errorEmbed], ephemeral: true });
}
}
});
// MongoDB model for warnings
const { Schema, model } = require('mongoose');
const warnSchema = new Schema({
userId: String,
guildId: String,
warnings: [
{
modId: String,
reason: String,
date: { type: Date, default: Date.now }
}
]
});
// MongoDB connection
mongoose.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useUnifiedTopology: true,
}).then(() => {
console.log('✅ Connected to MongoDB');
client.login(process.env.DISCORD_TOKEN);
}).catch(err => {
console.error('❌ MongoDB connection error:', err);
});