Initial commit
This commit is contained in:
68
index.js
Normal file
68
index.js
Normal file
@@ -0,0 +1,68 @@
|
||||
const { Client, GatewayIntentBits, Partials, ActivityType, Events, Collection } = require('discord.js');
|
||||
const { token, hypixelApiKey } = require('./config.json');
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
GatewayIntentBits.Guilds,
|
||||
GatewayIntentBits.GuildMessages,
|
||||
GatewayIntentBits.GuildMembers,
|
||||
GatewayIntentBits.MessageContent,
|
||||
],
|
||||
partials: [
|
||||
Partials.GuildMember,
|
||||
Partials.User
|
||||
]
|
||||
});
|
||||
|
||||
client.commands = new Collection();
|
||||
|
||||
//! commands
|
||||
const cmdPath = path.join(__dirname, 'commands');
|
||||
const cmdFiles = fs.readdirSync(cmdPath).filter(file => file.endsWith('.js'));
|
||||
|
||||
for (const file of cmdFiles) {
|
||||
|
||||
const filePath = path.join(cmdPath, file);
|
||||
const cmd = require(filePath);
|
||||
|
||||
if ('data' in cmd && 'execute' in cmd && cmd.type === 'slash') {
|
||||
client.commands.set(cmd.data.name, cmd);
|
||||
} else {
|
||||
console.log(`[WARNING] The command at ${filePath} is missing a required "data", "execute" or "type" property.`);
|
||||
}
|
||||
}
|
||||
|
||||
//! command handler
|
||||
client.on(Events.InteractionCreate, async interaction => {
|
||||
if(!interaction.isChatInputCommand()) return;
|
||||
|
||||
const command = interaction.client.commands.get(interaction.commandName);
|
||||
|
||||
if (!command) {
|
||||
console.error(`No command matching ${interaction.commandName} was found.`);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await command.execute(interaction);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true })
|
||||
}
|
||||
});
|
||||
|
||||
client.once(Events.Ready, c => {
|
||||
console.log(`Logged in as ${c.user.tag}!`);
|
||||
});
|
||||
|
||||
|
||||
client.on(Events.ClientReady, () => {
|
||||
client.user.setActivity({ name: 'illegitimate guild.', type: ActivityType.Watching });
|
||||
});
|
||||
client.on(Events.ClientReady, () => {
|
||||
client.user.setStatus('dnd');
|
||||
});
|
||||
|
||||
client.login(token);
|
||||
Reference in New Issue
Block a user