added mognodb database

This commit is contained in:
2025-01-30 20:15:50 +01:00
parent c913661109
commit 8fd4ed237b
11 changed files with 326 additions and 7 deletions
+27
View File
@@ -0,0 +1,27 @@
// exampleCommand.js
const { SlashCommandBuilder } = require('discord.js');
const { connectToDatabase } = require('../../db.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('example')
.setDescription('An example DB usage')
.addStringOption(option =>
option
.setName('message')
.setDescription('string to store')
.setRequired(true)),
async execute(interaction) {
const dbClient = await connectToDatabase();
const message = interaction.options.getString('message');
// Choose a DB + Collection
const db = dbClient.db('discord');
const collection = db.collection('test');
// Example: Insert something
await collection.insertOne({ userId: interaction.user.id, message: message });
await interaction.reply('Successfully inserted your data into MongoDB.');
},
};