1.2.0 • Published 1 year ago
disco.gy v1.2.0
Updated
fixed some bugs in giveaway end
disco.gy
A package for giveaways .
Version
discord.js@13 Now | discord.js@14 Soon
Examples
(/examples/giveaway.png)
Start
Start by creating a new GiveawayCreator.
const { Client } = require('discord.js');
const client = new Client();
const { GiveawayCreator } = require('disco.gy');
const Creator = new GiveawayCreator(client, 'mongodb://uri.com');
client.giveaways = Creator; // Access the Creator from anywhere.
All Methods
startGiveaway(options)
Creates a giveaway. Example:
client.on('messageCreate', async msg => {
if (msg.content.startsWith('$gstart')) {
const channel = msg.mentions.channels.first();
await client.giveaways.startGiveaway({
prize: 'Discord Nitro Classic',
channelId: channel.id,
guildId: msg.guild.id,// the guild
duration: 30000, // 30 Seconds
winners: 1, // 1 winner
hostedBy: msg.author.id
});
}
});
Slash
Creates a giveaway. Example:
const { MessageEmbed, MessageActionRow, MessageButton, MessageSelectMenu, Modal, TextInputComponent } = require("discord.js");
const { GiveawayCreator } = require('disco.gy');
const config = require('../../config/config');
const ms = require('ms')
module.exports = {
name: "gstart",
description: "Start giveaway",
settings: {
dev: false
},
options: [
{
name: 'time',
description: 'The time',
type: 3,
required: true
},{
name: 'winners',
description: 'The winners',
type: 3,
required: true
},{
name: 'prize',
description: 'The time',
type: 3,
required: true
},
],
async execute(client, interaction) {
const Creator = new GiveawayCreator(client, config.mongodb);
client.giveaways = Creator;
let p = interaction.options.getString('prize')
let w = interaction.options.getString('winners')
let t = interaction.options.getString('time')
let tt = ms(t)
await client.giveaways.startGiveaway({
prize: p,
channelId: interaction.channel.id,
guildId: interaction.guild.id,// the guild
duration: tt, // 30 Seconds
winners: w, // 1 winner
hostedBy: interaction.user.id
});
interaction.reply({content: 'Giveaway started', ephemeral: true})
}
}
endGiveaway(messageId)
Ends a giveaway. Example:
client.on('messageCreate', async msg => {
if (msg.content.startsWith('$gend')) {
const args = msg.content.split(' ').slice(1);
const ended = await client.giveaways.endGiveaway(args.join(' '));
if (!ended) {
return msg.channel.send('This giveaway has already ended');
}
else {
msg.channel.send('Ended the giveaway');
}
}
});
rerollGiveaway(messageId)
Rerolls a giveaway. Example:
client.on('messageCreate', async msg => {
if (msg.content.startsWith('$greroll')) {
const args = msg.content.split(' ').slice(1);
const rerolled = await client.giveaways.rerollGiveaway(args.join(' '));
if (!rerolled) {
return msg.channel.send('This giveaway hasn\'t ended');
}
else {
msg.channel.send('Rerolled the giveaway');
}
}
});
listGiveaways(guildId)
const prettyMilliseconds = require('pretty-ms'); // npm i pretty-ms
client.on('messageCreate', async msg => {
if (msg.content.startsWith('$glist')) {
const list = await client.giveaways.listGiveaways(msg.guild.id);
if (!list) {
return msg.channel.send('No active giveaways.');
} else {
msg.channel.send(`${list.map(i => `\`${i.messageId}\` - **${i.prize}** | ${prettyMilliseconds(i.timeRemaining)} | Host: **${i.hostedBy}**`).join('\n')}`)
}
}
});
Properties
Giveaway Properties
guildId
The guild ID of the giveaway.
channelId
The channel ID of the giveaway.
hostedBy
The ID of the person who hosted the giveaway.
messageId
The message ID of the giveaway.
startsOn
A date of when the giveaway started.
endsOn
A date of when the giveaway will end.
winners
The amount of winners the giveaway can have.
hasEnded
Whether the giveaway has ended.
duration
The duration of the giveaway in milliseconds.
prize
The prize of the giveaway.