Upload files to ''

This commit is contained in:
nodemixaholic 2024-03-25 17:27:57 +00:00
parent ce48fa8f68
commit ab8b848c74
2 changed files with 146 additions and 138 deletions

View file

@ -1,19 +1,21 @@
require('dotenv').config(); // Load environment variables from .env file require('dotenv').config(); // Load environment variables from .env file
const { Client, Intents } = require('discord.js'); const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.MESSAGE_CREATE] }); const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES // Add intents as needed
]
});
const { SlashCommandBuilder } = require('@discordjs/builders'); const { SlashCommandBuilder } = require('@discordjs/builders');
const { REST } = require('@discordjs/rest'); const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9'); const { Routes } = require('discord-api-types/v9');
const QuickDb = require('quick.db'); const db = require('quick.db');
const express = require('express'); const express = require('express');
// Initialize Express.js app // Initialize Express.js app
const app = express(); const app = express();
const PORT = process.env.PORT || 3000; const PORT = process.env.PORT || 3000;
// Set up Quick.db
const db = new QuickDb.Database();
// Set up Discord slash commands // Set up Discord slash commands
const commands = [ const commands = [
new SlashCommandBuilder() new SlashCommandBuilder()
@ -38,12 +40,18 @@ const rest = new REST({ version: '9' }).setToken(process.env.DISCORD_BOT_TOKEN);
try { try {
console.log('Started refreshing application (/) commands.'); console.log('Started refreshing application (/) commands.');
await rest.put( const applicationId = client.application?.id;
Routes.applicationCommands(process.env.DISCORD_CLIENT_ID), const guildId = client.guilds.cache.first()?.id;
{ body: commands },
);
console.log('Successfully reloaded application (/) commands.'); if (applicationId && guildId) {
await rest.put(
Routes.applicationGuildCommands(applicationId, guildId),
{ body: commands },
);
console.log('Successfully reloaded application (/) commands.');
} else {
console.error('Unable to retrieve application or guild ID.');
}
} catch (error) { } catch (error) {
console.error(error); console.error(error);
} }
@ -106,11 +114,10 @@ client.on('interactionCreate', async interaction => {
}); });
// Start the Express.js server for the XP API // Start the Express.js server for the XP API
app.get('/xp/:guildId/:userId', (req, res) => { app.get('/xp/:userId', (req, res) => {
const guildId = req.params.guildId;
const userId = req.params.userId; const userId = req.params.userId;
const xp = db.get(`xp.${userId}`) || 0; const xp = db.get(`xp.${userId}`) || 0;
res.json({ guildId, userId, xp }); res.json({ userId, xp });
}); });
app.listen(PORT, () => { app.listen(PORT, () => {

View file

@ -8,10 +8,11 @@
}, },
"dependencies": { "dependencies": {
"@discordjs/builders": "^1.7.0", "@discordjs/builders": "^1.7.0",
"@discordjs/rest": "^2.2.0",
"discord-api-types": "^0.24.0", "discord-api-types": "^0.24.0",
"discord.js": "^13.4.1", "discord.js": "^13.4.1",
"dotenv": "^10.0.0",
"express": "^4.17.1", "express": "^4.17.1",
"quick.db": "^9.1.7", "quick.db": "^9.1.7"
"dotenv": "^10.0.0"
} }
} }