added slash command and basic functionality

This commit is contained in:
2022-05-12 14:56:35 -05:00
parent e536d6b61c
commit fda4a09112
7 changed files with 298 additions and 40 deletions

40
bot.js

@ -1,19 +1,33 @@
const noblox = require("noblox.js");
const { Client, Intents } = require("discord.js");
const {cookie, token} = require("./config.json");
const fs = require('node:fs');
const { Client, Collection, Intents } = require("discord.js");
const {token} = require("./config.json");
function buyAsset(id) {
noblox.setCookie(cookie)
.then(async () => {
noblox.buy(921233306, 0)
.catch(async (error) => {
console.log("Could not purchase, error: ")
console.log(error)
});
});
const client = new Client({ intents: [Intents.FLAGS.GUILDS]});
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
// Set a new item in the Collection
// With the key as the command name and the value as the exported module
client.commands.set(command.data.name, command);
}
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]});
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
if (!command) 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("ready", () => {
console.log("Ready");