core: Update index.ts to autoload the new command
This commit is contained in:
parent
df94fb7fe5
commit
e911f3b2e0
1 changed files with 23 additions and 34 deletions
57
src/index.ts
57
src/index.ts
|
|
@ -1,7 +1,7 @@
|
||||||
import fs from 'node:fs';
|
import fs from 'node:fs';
|
||||||
import path from 'node:path';
|
import path from 'node:path';
|
||||||
import 'dotenv/config';
|
import 'dotenv/config';
|
||||||
import { Client, Collection, GatewayIntentBits } from 'discord.js';
|
import { Client, Collection, GatewayIntentBits, REST, Routes } from 'discord.js';
|
||||||
import { PrismaClient } from '@prisma/client';
|
import { PrismaClient } from '@prisma/client';
|
||||||
|
|
||||||
const prisma = new PrismaClient();
|
const prisma = new PrismaClient();
|
||||||
|
|
@ -15,13 +15,13 @@ const client = new Client({
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
client.login(process.env.DSC_TOKEN);
|
|
||||||
|
|
||||||
client.commands = new Collection();
|
client.commands = new Collection();
|
||||||
|
|
||||||
const commandFolderPath = path.join(__dirname, 'commands');
|
const commandFolderPath = path.join(__dirname, 'commands');
|
||||||
const commandFolders = fs.readdirSync(commandFolderPath);
|
const commandFolders = fs.readdirSync(commandFolderPath);
|
||||||
|
|
||||||
|
const commands = [];
|
||||||
|
|
||||||
console.log('\n🔍 | Commands search:');
|
console.log('\n🔍 | Commands search:');
|
||||||
for (const folder of commandFolders) {
|
for (const folder of commandFolders) {
|
||||||
const commandsPath = path.join(commandFolderPath, folder);
|
const commandsPath = path.join(commandFolderPath, folder);
|
||||||
|
|
@ -35,6 +35,7 @@ for (const folder of commandFolders) {
|
||||||
const command = commandModule.default || commandModule;
|
const command = commandModule.default || commandModule;
|
||||||
if ('data' in command && 'execute' in command) {
|
if ('data' in command && 'execute' in command) {
|
||||||
client.commands.set(command.data.name, command);
|
client.commands.set(command.data.name, command);
|
||||||
|
commands.push(command.data.toJSON());
|
||||||
console.log(`\t✅ | ${command.data.name}`);
|
console.log(`\t✅ | ${command.data.name}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -78,55 +79,43 @@ console.log('\n\n');
|
||||||
|
|
||||||
client.once('ready', async () => {
|
client.once('ready', async () => {
|
||||||
console.log(`🤖 | Connecté en tant que ${client.user?.tag}`);
|
console.log(`🤖 | Connecté en tant que ${client.user?.tag}`);
|
||||||
|
|
||||||
await prisma.bot.upsert({
|
await prisma.bot.upsert({
|
||||||
where: {
|
where: { id: 1 },
|
||||||
id: 1,
|
|
||||||
},
|
|
||||||
update: {},
|
update: {},
|
||||||
create: {},
|
create: {},
|
||||||
});
|
});
|
||||||
for (const [guildId, guild] of client.guilds.cache) {
|
for (const [guildId, guild] of client.guilds.cache) {
|
||||||
await prisma.guild.upsert({
|
await prisma.guild.upsert({
|
||||||
where: {
|
where: { id: guildId },
|
||||||
id: guildId,
|
|
||||||
},
|
|
||||||
update: {},
|
update: {},
|
||||||
create: {
|
create: { id: guildId },
|
||||||
id: guildId,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const members = await guild.members.fetch();
|
const members = await guild.members.fetch();
|
||||||
|
|
||||||
for (const [memberId] of members) {
|
for (const [memberId] of members) {
|
||||||
await prisma.user.upsert({
|
await prisma.user.upsert({
|
||||||
where: {
|
where: { id: memberId },
|
||||||
id: memberId,
|
|
||||||
},
|
|
||||||
update: {},
|
update: {},
|
||||||
create: {
|
create: { id: memberId },
|
||||||
id: memberId,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|
||||||
await prisma.guildUser.upsert({
|
await prisma.guildUser.upsert({
|
||||||
where: {
|
where: { userId_guildId: { userId: memberId, guildId } },
|
||||||
userId_guildId: {
|
|
||||||
userId: memberId,
|
|
||||||
guildId: guildId,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
update: {},
|
update: {},
|
||||||
create: {
|
create: { userId: memberId, guildId },
|
||||||
userId: memberId,
|
|
||||||
guildId: guildId,
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
console.log(`✅ | Guild ${guild.name} synchronisée avec ${members.size} membres.`);
|
||||||
console.log(
|
}
|
||||||
`✅ | Guild ${guild.name} synchronisée avec ${members.size} membres.`,
|
try {
|
||||||
|
const rest = new REST().setToken(process.env.DSC_TOKEN!);
|
||||||
|
const data = await rest.put(
|
||||||
|
Routes.applicationCommands(process.env.CLIENT_ID!),
|
||||||
|
{ body: commands },
|
||||||
);
|
);
|
||||||
|
console.log(`✅ | ${data.length} commandes déployées globalement.`);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.error('⚠️ | Erreur lors du déploiement des commandes :', err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
client.login(process.env.DSC_TOKEN);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue