UNPKG

loriapi

Version:

A simple library for fetching information from Loritta, a popular Discord bot made by the Brazilian developer MrPowerGamerBR.

45 lines 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const axios_1 = require("axios"); class GiveawayCreate { constructor(api, options) { this.api = api; this.options = options; } async createGiveaway(guildId) { try { // Prepara os dados para a requisição de forma condicional const data = { channelId: this.options.channelId, reason: this.options.reason, description: this.options.description, reaction: this.options.reaction, endsAt: this.options.endsAt, numberOfWinners: this.options.numberOfWinners, }; // Adiciona campos opcionais se estiverem definidos if (this.options.imageUrl) { data.imageUrl = this.options.imageUrl; } if (this.options.thumbnailUrl) { data.thumbnailUrl = this.options.thumbnailUrl; } if (this.options.color) { data.color = this.options.color; } const response = await axios_1.default.put(`https://api.loritta.website/v1/guilds/${guildId}/giveaways`, data, { headers: { 'Authorization': `Bearer ${this.api.loriKey}`, // Certifique-se de usar o formato correto 'Content-Type': 'application/json', }, }); console.log('Sorteio criado com sucesso:', response.data); } catch (error) { console.error('Erro ao criar sorteio:', error); throw error; // Você pode lançar o erro novamente ou tratá-lo de outra forma } } } exports.default = GiveawayCreate; //# sourceMappingURL=GivewayCreate.js.map