-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
135 lines (110 loc) · 4 KB
/
index.js
File metadata and controls
135 lines (110 loc) · 4 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
require('dotenv').config();
const path = require('path');
const fs = require('node:fs');
const { suggestionChannel } = require('./config.json');
const { Client, GatewayIntentBits, Partials, ActivityType, Collection, REST, Routes } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers
],
partials: [Partials.Message, Partials.Channel, Partials.Reaction]
});
client.commands = new Collection();
// load events
const eventsPath = path.join(__dirname, 'events');
const eventFolders = fs.readdirSync(eventsPath);
for (const folder of eventFolders) {
console.log(`Loading events from ${folder}`);
const eventPath = path.join(eventsPath, folder);
const eventFiles = fs.readdirSync(eventPath);
for (const file of eventFiles) {
console.log(`Loading event ${file}`);
const filePath = path.join(eventPath, file);
const event = require(filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client));
} else {
client.on(event.name, (...args) => event.execute(...args, client));
}
}
}
// load commands
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
client.once('ready', () => {
console.log(`${client.user.username} has logged in`);
client.user.setPresence({
activities: [{
name: 'without frameworks',
type: ActivityType.Playing
}],
status: 'online'
});
});
client.on('interactionCreate', async interaction => {
const command = client.commands.get(interaction.commandName);
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
}
});
client.on('message', (message) => {
if(message.mentions.users.first() && message.mentions.users.first().username === 'Vanilla') {
message.reply('Il prefisso per i comandi è `js`. Prova `jshelp` 😉');
}
if (message.channel.name == suggestionChannel && !message.author.bot) {
if (!(message.content.startsWith('jssuggest') || message.content.startsWith('jsplz'))) {
message.delete();
}
}
});
client.on('error', console.error);
async function deployCommands() {
try {
const commands = [];
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
const rest = new REST().setToken(process.env.VANILLA_BOT_TOKEN);
console.log(`Started refreshing ${commands.length} application (/) commands.`);
const data = await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID),
{ body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}
}
deployCommands().then(() => {
client.login(process.env.VANILLA_BOT_TOKEN);
});