implement changes to commands and templates
This commit is contained in:
@@ -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 });
|
||||
|
||||
@@ -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 } },
|
||||
|
||||
Reference in New Issue
Block a user