63 lines
1.8 KiB
JavaScript
63 lines
1.8 KiB
JavaScript
import {
|
|
Client,
|
|
GatewayIntentBits,
|
|
REST,
|
|
Routes,
|
|
Collection,
|
|
EmbedBuilder,
|
|
ChannelType,
|
|
PermissionsBitField
|
|
} from "discord.js";
|
|
import config from "./config.json" with { type: "json" };
|
|
import fs from "fs";
|
|
|
|
export const client = new Client({intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildVoiceStates,]});
|
|
|
|
const clientCommands = new Collection();
|
|
|
|
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
|
|
const commands = [];
|
|
for (const file of commandFiles) {
|
|
|
|
const command = await import(`./commands/${file}`)
|
|
commands.push(command.data.toJSON())
|
|
if (command.data.name) {
|
|
clientCommands.set(command.data.name, command);
|
|
}
|
|
}
|
|
|
|
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));;
|
|
for (const file of eventFiles) {
|
|
const event = await import(`./events/${file}`)
|
|
const name = file.split('.')[0];
|
|
if (event.once) {
|
|
client.once(name, (...args) => event.execute(...args));
|
|
} else {
|
|
client.on(name, (...args) => event.execute(...args));
|
|
}
|
|
}
|
|
|
|
//console.log(clientCommands);
|
|
|
|
const rest = new REST({version: '10'}).setToken(config.token);
|
|
|
|
(async () => {
|
|
try {
|
|
console.log('Started refreshing application (/) commands.');
|
|
|
|
await rest.put(Routes.applicationCommands(config.id), {body: commands});
|
|
|
|
console.log('Successfully reloaded application (/) commands.');
|
|
} catch (error) {
|
|
console.error(error);
|
|
}
|
|
})();
|
|
|
|
client.on('interactionCreate', async interaction => {
|
|
if (!interaction.isChatInputCommand()) return;
|
|
const command = clientCommands.get(interaction.commandName);
|
|
|
|
await command.execute(interaction)
|
|
});
|
|
|
|
client.login(config.token); |