Winnex
Winnex
DIAdiscord.js - Imagine an app
Created by Winnex on 12/23/2023 in #djs-questions
Editing embeds to preserve original content
Thank you so, so much!
19 replies
DIAdiscord.js - Imagine an app
Created by Winnex on 12/23/2023 in #djs-questions
Editing embeds to preserve original content
// Create a new instance of EmbedBuilder
const editedEmbed = new EmbedBuilder();
const oldEmbed = interaction.message.embeds[0];

// Assuming oldEmbed has a "fields" property containing an array of fields
const originalFields = oldEmbed.fields;

// Create a string to hold the original fields
let originalFieldsString = '';

// Iterate over the originalFields array and append each field's name and value to the string
originalFields.forEach(field => {
originalFieldsString += `**${field.name}\n** ${field.value}\n\n`;
});

// Edit the original embed to show the rejected message along with the original data
editedEmbed.setColor(0xcb380c)
.setTitle('Afvist med grund!')
.setDescription(`<@${user.id}> Allowlist ansøgning er blevet afvist af <@${interaction.user.id}>!\n\n${originalFieldsString}**Bemærkninger fra afvisningen:**\n${reason}`)
.setTimestamp();

// Remove buttons below the application embed when rejected
const components = [];

// Update the message with the modified embed and removed components
await interaction.message.edit({ embeds: [editedEmbed], components });
}

export { onClickDeclineReasonAllowlist };
// Create a new instance of EmbedBuilder
const editedEmbed = new EmbedBuilder();
const oldEmbed = interaction.message.embeds[0];

// Assuming oldEmbed has a "fields" property containing an array of fields
const originalFields = oldEmbed.fields;

// Create a string to hold the original fields
let originalFieldsString = '';

// Iterate over the originalFields array and append each field's name and value to the string
originalFields.forEach(field => {
originalFieldsString += `**${field.name}\n** ${field.value}\n\n`;
});

// Edit the original embed to show the rejected message along with the original data
editedEmbed.setColor(0xcb380c)
.setTitle('Afvist med grund!')
.setDescription(`<@${user.id}> Allowlist ansøgning er blevet afvist af <@${interaction.user.id}>!\n\n${originalFieldsString}**Bemærkninger fra afvisningen:**\n${reason}`)
.setTimestamp();

// Remove buttons below the application embed when rejected
const components = [];

// Update the message with the modified embed and removed components
await interaction.message.edit({ embeds: [editedEmbed], components });
}

export { onClickDeclineReasonAllowlist };
19 replies
DIAdiscord.js - Imagine an app
Created by Winnex on 12/23/2023 in #djs-questions
Editing embeds to preserve original content
let reason; // Declare the variable outside the try-catch block

try {
const modal = new ModalBuilder()
.setCustomId('reasonInputModal')
.setTitle('Grund til afvisning');

const reasonInput = new TextInputBuilder()
.setCustomId('typereason')
.setLabel("Grund til afvisning")
.setMaxLength(200)
.setMinLength(3)
.setRequired(true)
.setStyle(TextInputStyle.Short);

modal.addComponents(
new ActionRowBuilder<TextInputBuilder>().addComponents(reasonInput),
);

await interaction.showModal(modal);

const submission = await interaction.awaitModalSubmit({ time: 60000 });

// Get the input value from the submission
reason = submission.fields.getTextInputValue('typereason');

// Fetch user object
const userObj = await client.users.fetch(user.id);

// Send rejection message to the user
await userObj.send({
embeds: [new EmbedBuilder()
.setColor(0xcb380c)
.setTitle('Afvist.')
.setDescription(`Din ansøgning til allowlist er desværre blevet afvist.\n\nTypisk er det grundet ansøgningen mangler vigtig fyld, og derved ikke giver os indblik i kvaliteten af ansøgningen og dig som spiller.\n\nBemærkninger fra afvisningen:\n${reason}\n`)
.setThumbnail('https://i.imgur.com/UX6VVZz.png')
.setFooter({ text: 'Mvh.' })
.setTimestamp()
]
});
} catch (error) {
console.error(`Fejl ved afsendelse af privat besked: ${error}`);
}
let reason; // Declare the variable outside the try-catch block

try {
const modal = new ModalBuilder()
.setCustomId('reasonInputModal')
.setTitle('Grund til afvisning');

const reasonInput = new TextInputBuilder()
.setCustomId('typereason')
.setLabel("Grund til afvisning")
.setMaxLength(200)
.setMinLength(3)
.setRequired(true)
.setStyle(TextInputStyle.Short);

modal.addComponents(
new ActionRowBuilder<TextInputBuilder>().addComponents(reasonInput),
);

await interaction.showModal(modal);

const submission = await interaction.awaitModalSubmit({ time: 60000 });

// Get the input value from the submission
reason = submission.fields.getTextInputValue('typereason');

// Fetch user object
const userObj = await client.users.fetch(user.id);

// Send rejection message to the user
await userObj.send({
embeds: [new EmbedBuilder()
.setColor(0xcb380c)
.setTitle('Afvist.')
.setDescription(`Din ansøgning til allowlist er desværre blevet afvist.\n\nTypisk er det grundet ansøgningen mangler vigtig fyld, og derved ikke giver os indblik i kvaliteten af ansøgningen og dig som spiller.\n\nBemærkninger fra afvisningen:\n${reason}\n`)
.setThumbnail('https://i.imgur.com/UX6VVZz.png')
.setFooter({ text: 'Mvh.' })
.setTimestamp()
]
});
} catch (error) {
console.error(`Fejl ved afsendelse af privat besked: ${error}`);
}
19 replies
DIAdiscord.js - Imagine an app
Created by Winnex on 12/23/2023 in #djs-questions
Editing embeds to preserve original content
I've grown blind on this block of code, where do I need to implement the resolve to have it properly close the reason input modal after hitting submit?
19 replies
DIAdiscord.js - Imagine an app
Created by Winnex on 12/23/2023 in #djs-questions
Editing embeds to preserve original content
I have an application that is as, handled by another typescript. Then my code when I hit the deny with reason button opens a modal, prompting for the reason. When I hit submit in that it doesn’t close, and I get the error, but the meaaage with the rejection and added reason is successful, the application embed is also changed to rejected and the content preserved while noting the reason at the end. But the reason modal doesn’t actually close and the error pops up when hitting submit. What line should I add to resolve/properly close the reason modal when I have hit submit.
19 replies
DIAdiscord.js - Imagine an app
Created by Winnex on 12/23/2023 in #djs-questions
Editing embeds to preserve original content
How would i Apply those solutions in the code?
19 replies
DIAdiscord.js - Imagine an app
Created by Winnex on 12/23/2023 in #djs-questions
Editing embeds to preserve original content
I got it all working, but the modal that pops up now, to prompt the interactionuser to submit a reason does not close after hitting submit, instead it waits and gives a "something went wrong, try again" error, but it doesn't fail. The message is sent properly to the applicant's DMs, and the original embed is updated with all the original content of the application + the reason that had been submitted. It just doesn't close the actual modal when submitting a reason, and gives that error, but it is 100% functional and works as intended otherwise.
19 replies
DIAdiscord.js - Imagine an app
Created by Winnex on 12/23/2023 in #djs-questions
Editing embeds to preserve original content
I can't seem to find any documentation on the from() method, how would I apply it in my example here?
19 replies
DIAdiscord.js - Imagine an app
Created by Winnex on 12/23/2023 in #djs-questions
Editing embeds to preserve original content
This is how I build the embed when editing it:
// Create a new instance of EmbedBuilder
const editedEmbed = new EmbedBuilder();


// Edit the original embed to show the accepted message
editedEmbed.setColor(0x7ACB0C)
.setTitle('Accepteret!')
.setDescription(`<@${user.id}> Allowlist ansøgning er blevet godkendt af <@${interaction.user.id}>!`)
.setTimestamp();

// Update the message with the modified embed
await interaction.message.edit({ embeds: [editedEmbed] });

// ...
// Create a new instance of EmbedBuilder
const editedEmbed = new EmbedBuilder();


// Edit the original embed to show the accepted message
editedEmbed.setColor(0x7ACB0C)
.setTitle('Accepteret!')
.setDescription(`<@${user.id}> Allowlist ansøgning er blevet godkendt af <@${interaction.user.id}>!`)
.setTimestamp();

// Update the message with the modified embed
await interaction.message.edit({ embeds: [editedEmbed] });

// ...
How can I apply the from() method here to retrieve the data from the other file and add them, so the original application data "stays"? I'm a bit lost here 😛
19 replies
DIAdiscord.js - Imagine an app
Created by Winnex on 12/23/2023 in #djs-questions
Editing embeds to preserve original content
This is my listener.ts file:
const embed = new EmbedBuilder()
.setColor(0xEB8922)
.setTitle(interactionUser.id+"")
.setThumbnail(image)
.setDescription(`Ansøgning fra <@${interactionUser.id}>`)
.addFields(
{ name: 'Hvad er din alder?', value: alder, inline: true },
{ name: 'Hvor mange timer har du på FiveM?', value: timer, inline: true },
{ name: 'Hvor har du RP erfaring fra?', value: erfaring, inline: false },
{ name: 'Hvorfor vil du gerne ind på serveren?', value: hvorfor, inline: false },
{ name: 'Hvordan bidrager din karakter til serveren?', value: baggrund, inline: false })
.setTimestamp()

const accept_Allowlist = new ButtonBuilder()
.setCustomId('accept_Allowlist')
.setLabel('Godkend')
.setEmoji("✅")
.setStyle(ButtonStyle.Success);
const decline = new ButtonBuilder()
.setCustomId('decline_Allowlist_request')
.setLabel('Afvis')
.setEmoji("❌")
.setStyle(ButtonStyle.Danger);
const decline_reson = new ButtonBuilder()
.setCustomId('decline_reson_request')
.setLabel('Afvis med grund')
.setEmoji("❌")
.setStyle(ButtonStyle.Danger);

const row = new ActionRowBuilder()
.addComponents(accept_Allowlist, decline, decline_reson);

channel.send({ components: [row], embeds: [embed]});
}
const embed = new EmbedBuilder()
.setColor(0xEB8922)
.setTitle(interactionUser.id+"")
.setThumbnail(image)
.setDescription(`Ansøgning fra <@${interactionUser.id}>`)
.addFields(
{ name: 'Hvad er din alder?', value: alder, inline: true },
{ name: 'Hvor mange timer har du på FiveM?', value: timer, inline: true },
{ name: 'Hvor har du RP erfaring fra?', value: erfaring, inline: false },
{ name: 'Hvorfor vil du gerne ind på serveren?', value: hvorfor, inline: false },
{ name: 'Hvordan bidrager din karakter til serveren?', value: baggrund, inline: false })
.setTimestamp()

const accept_Allowlist = new ButtonBuilder()
.setCustomId('accept_Allowlist')
.setLabel('Godkend')
.setEmoji("✅")
.setStyle(ButtonStyle.Success);
const decline = new ButtonBuilder()
.setCustomId('decline_Allowlist_request')
.setLabel('Afvis')
.setEmoji("❌")
.setStyle(ButtonStyle.Danger);
const decline_reson = new ButtonBuilder()
.setCustomId('decline_reson_request')
.setLabel('Afvis med grund')
.setEmoji("❌")
.setStyle(ButtonStyle.Danger);

const row = new ActionRowBuilder()
.addComponents(accept_Allowlist, decline, decline_reson);

channel.send({ components: [row], embeds: [embed]});
}
19 replies
DIAdiscord.js - Imagine an app
Created by Winnex on 12/23/2023 in #djs-questions
Editing embeds to preserve original content
Since it's another file?
19 replies
DIAdiscord.js - Imagine an app
Created by Winnex on 12/23/2023 in #djs-questions
Editing embeds to preserve original content
So here I would need to use the from() method?
19 replies
DIAdiscord.js - Imagine an app
Created by Winnex on 12/23/2023 in #djs-questions
Editing embeds to preserve original content
The setdescription is handled both places. When the application is first sent in, it sets the embed description to all my fields they should fill out. Then when I hit accept, the second codeblock I sent, it sets the description again, but here it removes the original application content.
19 replies