Small fix
This commit is contained in:
@@ -15,11 +15,9 @@ module.exports = {
|
||||
const dbClient = await connectToDatabase();
|
||||
const db = dbClient.db('discord');
|
||||
const collection = db.collection('currency');
|
||||
|
||||
const target = interaction.options.getUser('user') ?? interaction.user;
|
||||
const targetData = await collection.findOne({ userID: target.id });
|
||||
const balance = targetData?.balance ?? 0;
|
||||
|
||||
return interaction.reply({
|
||||
content: `${target.tag} has **${balance}** coins.`,
|
||||
});
|
||||
|
||||
@@ -9,12 +9,10 @@ const formatDuration = (ms) => {
|
||||
const hours = Math.floor(totalSeconds / 3600);
|
||||
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||
const seconds = totalSeconds % 60;
|
||||
|
||||
const parts = [];
|
||||
if (hours) parts.push(`${hours}h`);
|
||||
if (minutes) parts.push(`${minutes}m`);
|
||||
if (!hours && !minutes) parts.push(`${seconds}s`);
|
||||
|
||||
return parts.join(' ');
|
||||
};
|
||||
|
||||
@@ -28,11 +26,9 @@ module.exports = {
|
||||
const db = dbClient.db('discord');
|
||||
const collection = db.collection('currency');
|
||||
const now = new Date();
|
||||
|
||||
const userId = interaction.user.id;
|
||||
const userData = await collection.findOne({ userID: userId });
|
||||
const lastClaim = userData?.lastClaimedAt ? new Date(userData.lastClaimedAt) : null;
|
||||
|
||||
if (lastClaim) {
|
||||
const elapsed = now - lastClaim;
|
||||
if (elapsed < COOLDOWN_MS) {
|
||||
@@ -43,7 +39,6 @@ module.exports = {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
await collection.updateOne(
|
||||
{ userID: userId },
|
||||
{
|
||||
@@ -52,7 +47,6 @@ module.exports = {
|
||||
},
|
||||
{ upsert: true }
|
||||
);
|
||||
|
||||
return interaction.reply({
|
||||
content: `You earned **${REWARD_AMOUNT}** coins! Come back tomorrow for more.`,
|
||||
});
|
||||
|
||||
@@ -22,23 +22,19 @@ module.exports = {
|
||||
const dbClient = await connectToDatabase();
|
||||
const target = interaction.options.getUser('target');
|
||||
const amount = interaction.options.getInteger('amount');
|
||||
|
||||
if (target.bot) {
|
||||
return interaction.reply({
|
||||
content: 'You cannot grant coins to bot accounts.',
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
const db = dbClient.db('discord');
|
||||
const collection = db.collection('currency');
|
||||
|
||||
await collection.updateOne(
|
||||
{ userID: target.id },
|
||||
{ $inc: { balance: amount } },
|
||||
{ upsert: true }
|
||||
);
|
||||
|
||||
return interaction.reply({
|
||||
content: `You granted **${amount}** coins to ${target.tag}.`,
|
||||
});
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// exampleCommand.js
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
const { connectToDatabase } = require('../../db.js');
|
||||
|
||||
@@ -15,14 +14,9 @@ module.exports = {
|
||||
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.');
|
||||
},
|
||||
};
|
||||
|
||||
@@ -30,7 +30,6 @@ module.exports = {
|
||||
ephemeral: true,
|
||||
});
|
||||
}
|
||||
|
||||
await member.kick(reason);
|
||||
await recordModerationAction({
|
||||
guildId: interaction.guildId,
|
||||
@@ -40,7 +39,6 @@ module.exports = {
|
||||
reason,
|
||||
metadata: {},
|
||||
});
|
||||
|
||||
await interaction.reply(`Kicked ${user.tag} for: ${reason}`);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
Reference in New Issue
Block a user