discord-giveaways-s
Version:
Advanced module for creating and managing giveaways in Discord bots.
42 lines (32 loc) • 1.06 kB
JavaScript
/**
* Starts a giveaway: sets status to "running" and ended to false.
*
* @param {Object} options
* @param {string} options.storage - Path to the JSON file containing giveaways
* @param {string} options.giveawayId - Giveaway ID
* @throws {Error} if the giveawayId does not exist
*/
const fs = require("fs");
const path = require("path");
function GiveawayStart({ storage, giveawayId }) {
try {
const storagePath = path.resolve(storage);
if (!fs.existsSync(storagePath)) {
throw new Error(`Storage file not found at path: ${storagePath}`);
}
const data = JSON.parse(fs.readFileSync(storagePath, "utf8"));
if (!data[giveawayId]) {
throw new Error(`Giveaway with ID '${giveawayId}' does not exist.`);
}
data[giveawayId].status = "running";
data[giveawayId].ended = false;
fs.writeFileSync(storagePath, JSON.stringify(data, null, 2));
return true;
} catch (error) {
console.error(error);
return false;
}
}
module.exports = {
GiveawayStart,
};