Penitent
Penitent
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
got it, it works now! thanks @duck
35 replies
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
sorry
35 replies
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
i thought you were asking if in the initial interaction i was passing an empty array for embeds and then populating
35 replies
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
ahh sorry i misunderstood
35 replies
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
its an array of only 1 element
35 replies
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
function createPollEmbed(){
console.log(votes)

const pollEmbed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle(pollTitle)
.setDescription('Choose one of the following options')
.addFields(
{ name: '\u200B', value: `${firstChoice} - ${calculatePercentage(votes.firstChoice, votes.total)}
${':blue_square:'.repeat(calculateNumSquares(votes.firstChoice, votes.total))}${':black_large_square:'.repeat((10 - calculateNumSquares(votes.firstChoice, votes.total)))}
${secondChoice} - ${calculatePercentage(votes.secondChoice, votes.total)}
${':blue_square:'.repeat(calculateNumSquares(votes.secondChoice, votes.total))}${':black_large_square:'.repeat((10 - calculateNumSquares(votes.secondChoice, votes.total)))}
${thirdChoice} - ${calculatePercentage(votes.thirdChoice, votes.total)}
${':blue_square:'.repeat(calculateNumSquares(votes.thirdChoice, votes.total))}${':black_large_square:'.repeat((10 - calculateNumSquares(votes.thirdChoice, votes.total)))}` },
);
return pollEmbed;
}
function createPollEmbed(){
console.log(votes)

const pollEmbed = new EmbedBuilder()
.setColor(0x0099FF)
.setTitle(pollTitle)
.setDescription('Choose one of the following options')
.addFields(
{ name: '\u200B', value: `${firstChoice} - ${calculatePercentage(votes.firstChoice, votes.total)}
${':blue_square:'.repeat(calculateNumSquares(votes.firstChoice, votes.total))}${':black_large_square:'.repeat((10 - calculateNumSquares(votes.firstChoice, votes.total)))}
${secondChoice} - ${calculatePercentage(votes.secondChoice, votes.total)}
${':blue_square:'.repeat(calculateNumSquares(votes.secondChoice, votes.total))}${':black_large_square:'.repeat((10 - calculateNumSquares(votes.secondChoice, votes.total)))}
${thirdChoice} - ${calculatePercentage(votes.thirdChoice, votes.total)}
${':blue_square:'.repeat(calculateNumSquares(votes.thirdChoice, votes.total))}${':black_large_square:'.repeat((10 - calculateNumSquares(votes.thirdChoice, votes.total)))}` },
);
return pollEmbed;
}
35 replies
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
const response = await modalSubmission.reply({ embeds: [createPollEmbed(votes)], components: [row], fetchReply: true });

const collector = response.createMessageComponentCollector({ componentType: ComponentType.Button, time: 5_000 });

collector.on('collect', i => {
if (voters.has(i.user.id)) {
i.reply({content: `You've already voted on this poll!`, ephemeral: true});
}
else {
voters.add(i.user.id);
switch(i.customId){
case 'firstChoiceButton':
votes.firstChoice = votes.firstChoice += 1;
votes.total = votes.total += 1;
console.log(votes);
i.update({embeds: [createPollEmbed(votes)], components: [row], fetchReply: true})
break;
case 'secondChoiceButton':
votes.secondChoice = votes.secondChoice += 1;
votes.total = votes.total += 1;
console.log(votes);
i.update({embeds: [createPollEmbed(votes)], components: [row], fetchReply: true})
break;
case 'thirdChoiceButton':
votes.thirdChoice = votes.thirdChoice += 1;
votes.total = votes.total += 1;
console.log(votes);
i.update({embeds: [createPollEmbed(votes)], components: [row], fetchReply: true})
}
}

});
collector.on('end', i => {
i.first().editReply({content: 'hello'})
})
const response = await modalSubmission.reply({ embeds: [createPollEmbed(votes)], components: [row], fetchReply: true });

const collector = response.createMessageComponentCollector({ componentType: ComponentType.Button, time: 5_000 });

collector.on('collect', i => {
if (voters.has(i.user.id)) {
i.reply({content: `You've already voted on this poll!`, ephemeral: true});
}
else {
voters.add(i.user.id);
switch(i.customId){
case 'firstChoiceButton':
votes.firstChoice = votes.firstChoice += 1;
votes.total = votes.total += 1;
console.log(votes);
i.update({embeds: [createPollEmbed(votes)], components: [row], fetchReply: true})
break;
case 'secondChoiceButton':
votes.secondChoice = votes.secondChoice += 1;
votes.total = votes.total += 1;
console.log(votes);
i.update({embeds: [createPollEmbed(votes)], components: [row], fetchReply: true})
break;
case 'thirdChoiceButton':
votes.thirdChoice = votes.thirdChoice += 1;
votes.total = votes.total += 1;
console.log(votes);
i.update({embeds: [createPollEmbed(votes)], components: [row], fetchReply: true})
}
}

});
collector.on('end', i => {
i.first().editReply({content: 'hello'})
})
35 replies
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
No description
35 replies
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
ahhh it works! however it doesnt remove the embed
35 replies
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
ahhh okay, that makes sense, so then it would be i.first().editReply()?
35 replies
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
or something like that
35 replies
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
I wanna take this message and update it with saying "the poll has ended, B has the most votes with 100% of the votes"
35 replies
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
No description
35 replies
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
i really only wanna edit the message itself
35 replies
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
the collected items are interactions to buttons
35 replies
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
i did not know about native polls 😅 i'll def take a look
35 replies
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
" throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData); ^ DiscordAPIError[10008]: Unknown Message"
35 replies
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
also if i try interaction.editreply
35 replies
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
fair point, i have this line which sends the original embed: const response = await modalSubmission.reply({ embeds: [createPollEmbed(votes)], components: [row], fetchReply: true }); and i tried updating it with response.editReply, but that is also apparently not a valid function (i got editReply from this: https://discordjs.guide/slash-commands/response-methods.html#ephemeral-responses)
35 replies
DIAdiscord.js - Imagine an app
Created by Penitent on 3/27/2024 in #djs-questions
Using collector.on('end') to edit reply?
neither i.update() nor i.editReply() are actual functions, and im pretty sure its cause i is an object map
35 replies