feat: commands

This commit is contained in:
TresAbhi committed 2023-04-18 23:34:05 +00:00
1 parent 2e60df7776
commit 4b5caa6059
3 files changed
+80 -3

No files matched your search

+3 -1
View File
@@ -1,3 +1,5 @@
{
"token": "<TOKEN>"
"token": "",
"clientId": "",
"guildId": ""
}
+9
View File
@@ -0,0 +1,9 @@
import { SlashCommandBuilder } from 'discord.js';
export const data = new SlashCommandBuilder()
.setName('verify')
.setDescription('Verifies the user with Blitz');
export async function execute(interaction) {
await interaction.reply('uwu i done nothin here uwu');
}
+68 -2
View File
@@ -1,5 +1,13 @@
import { faker } from '@faker-js/faker';
import { Client, EmbedBuilder, GatewayIntentBits } from 'discord.js';
import {
Client,
Collection,
EmbedBuilder,
GatewayIntentBits,
REST,
Routes,
} from 'discord.js';
import { readdirSync } from 'fs';
import config from '../config.json' assert { type: 'json' };
const VERIFY_CHANNEL = '1097677884266643527';
@@ -9,7 +17,9 @@ const client = new Client({
});
client.on('error', console.error);
client.on('ready', (c) => console.log(`Logged in as ${client.user.tag}!`));
client.on('ready', (c) => {
console.log(`Logged in as ${c.user.tag}!`);
});
client.on('guildMemberAdd', (member) => {
member.guild.channels.cache.get(VERIFY_CHANNEL).send({
@@ -26,4 +36,60 @@ client.on('guildMemberAdd', (member) => {
});
});
client.commands = new Collection();
client.on('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);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({
content: 'There was an error while executing this command!',
ephemeral: true,
});
} else {
await interaction.reply({
content: 'There was an error while executing this command!',
ephemeral: true,
});
}
}
});
const commands = [];
const foldersPath = 'src/commands/';
const commandFolders = readdirSync(foldersPath);
for (const file of commandFolders) {
const command = await import(`./commands/${file}`);
commands.push(command.data.toJSON());
client.commands.set(command.data.name, command);
}
// Construct and prepare an instance of the REST module
const rest = new REST().setToken(config.token);
try {
console.log(`Started refreshing ${commands.length} command(s).`);
const data = await rest.put(
Routes.applicationGuildCommands(config.clientId, config.guildId),
{ body: commands },
);
console.log(`Successfully reloaded ${data.length} command(s).`);
} catch (error) {
console.error(error);
}
client.login(config.token);