Closed inxec closed 4 years ago
Hello, you can use the following code:
if(message.content === "list"){
// Get all the giveaways for the current guild
let giveaways = client.giveawaysManager.giveaways.filter((g) => g.guildID === message.guild.id);
// Keep the giveaways that are not ended
let notEndedGiveaways = giveaways.filter((g) => !g.ended);
message.channel.send(`Here are the current giveaways: ${notEndedGiveaways.map((g) => g.messageID).join(', ')}`);
}
This will send something like:
Here are the current giveaways: 618121508929142833, 618120950386262056, 665941399211868200
Hello, you can use the following code:
if(message.content === "list"){ // Get all the giveaways for the current guild let giveaways = client.giveawaysManager.giveaways.filter((g) => g.guildID === message.guild.id); // Keep the giveaways that are not ended let notEndedGiveaways = giveaways.filter((g) => !g.ended); message.channel.send(`Here are the current giveaways: ${notEndedGiveaways.map((g) => g.messageID).join(', ')}`); }
This will send something like:
Here are the current giveaways: 618121508929142833, 618120950386262056, 665941399211868200
Is there a way to show the prize?
const giveaways = client.giveawaysManager.giveaways.filter((g) => g.guildID === message.guild.id);
const notEndedGiveaways = giveaways.filter((g) => !g.ended);
if(notEndedGiveaways.length === 0) return message.channel.send('No giveaway currently active on this server.');
message.channel.send(`Here are the current giveaways : \n${notEndedGiveaways.map((g) => `${g.data.prize} - ${g.messageID}`).join('\n')}`);
const giveaways = client.giveawaysManager.giveaways.filter((g) => g.guildID === message.guild.id); const notEndedGiveaways = giveaways.filter((g) => !g.ended); if(notEndedGiveaways.length === 0) return message.channel.send('No giveaway currently active on this server.'); message.channel.send(`Here are the current giveaways : \n${notEndedGiveaways.map((g) => `${g.data.prize} - ${g.messageID}`).join('\n')}`);
Hi! Last question, is there a way to show the user who hosted the giveaway, and the time remaining? ❤ Thanks
To display the user who hosts the giveaway you can use g.hostedBy, for the time you can subtract g.endAt and g.startAt (i think)
Is there any way you could use .hostedBy without pinging the person?
You could use something like that:
message.channel.send(`Here are the current giveaways : \n${notEndedGiveaways.map((g) => {
const userID = g.data.hostedBy.split('<@')[0].split('>')[0];
const user = message.client.users.cache.get(userID);
return `${user.tag} - ${g.messageID}`;
}).join('\n')}`;
This is not really clean but at this time it's the only way... Or you could use a regular expression but it's not easy to understand.
Thanks!
I thought it was g.hostedBy and not g.data.hostedBy.
How do I make it send a message if there are no active giveaways. I've tried using if statements but then I always get a DiscordAPIError that says: Cannot send a empty message.
const giveaways = message.client.GiveawaysManager.giveaways.filter((g) => g.guildID === message.guild.id);
const notEndedGiveaways = giveaways.filter((g) => !g.ended);
if(notEndedGiveaways.length === 0) return message.channel.send('No giveaway in progress on this server.');
How do you get the channel?
const giveaways = client.giveawaysManager.giveaways.filter((g) => g.guildID === message.guild.id);
const notEndedGiveaways = giveaways.filter((g) => !g.ended);
if(notEndedGiveaways.length === 0) return message.channel.send('No giveaway currently active on this server.');
message.channel.send(`Here are the current giveaways : \n${notEndedGiveaways.map((g) => `${g.data.prize} - ${g.messageID} - ${g.channelID}`).join('\n')}`);
const giveaways = client.giveawaysManager.giveaways.filter((g) => g.guildID === message.guild.id && client.channels.cache.get(g.channelID));
You all have to use this because otherwise if a channel where a giveaway is hosted in, gets deleted, the command would still display it as active
It would be REALLY cool if theres actually a way to list ALL the running giveaways in a server. I saw the "Fetch Giveaways" section in discord-giveaways package, but I dont really understand how it works? Well I mean i do understand the let onServer = client.giveawaysManager.giveaways.filter((g) => g.guildID === "guild id"), but idk how use that to show the running giveaways.