implement changes to commands and templates

This commit is contained in:
2026-04-08 14:20:54 +02:00
parent e90b8b4d85
commit 65a281dbcb
15 changed files with 326 additions and 59 deletions
+6
View File
@@ -14,6 +14,12 @@ module.exports = {
async execute(interaction) {
const dbClient = await connectToDatabase();
const message = interaction.options.getString('message');
if (message.length > 500) {
return interaction.reply({
content: 'Message must be 500 characters or fewer.',
ephemeral: true,
});
}
const db = dbClient.db('discord');
const collection = db.collection('test');
await collection.insertOne({ userId: interaction.user.id, message: message });
+8 -9
View File
@@ -40,22 +40,21 @@ module.exports = {
}
const senderId = interaction.user.id;
const senderData = await collection.findOne({ userID: senderId });
const senderBalance = senderData?.balance ?? 0;
const debitResult = await collection.findOneAndUpdate(
{ userID: senderId, balance: { $gte: amount } },
{ $inc: { balance: -amount } },
{ returnDocument: 'after' }
);
if (senderBalance < amount) {
if (!debitResult.value) {
const senderData = await collection.findOne({ userID: senderId });
const senderBalance = senderData?.balance ?? 0;
return interaction.reply({
content: `You only have **${senderBalance}** coins available.`,
ephemeral: true,
});
}
await collection.updateOne(
{ userID: senderId },
{ $inc: { balance: -amount } },
{ upsert: true }
);
await collection.updateOne(
{ userID: target.id },
{ $inc: { balance: amount } },