Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Events, EmbedBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder, ModalBuilder, TextInputBuilder, TextInputStyle } = require('discord.js');
- const { trelloKey, trelloToken } = require('../config.json');
- const Trello = require("trello");
- const trello = new Trello(trelloKey, trelloToken);
- module.exports = {
- name: Events.InteractionCreate,
- async execute(interaction) {
- if (interaction.isChatInputCommand()) {
- const command = interaction.client.commands.get(interaction.commandName);
- if (!command) {
- console.error(`No command matching ${interaction.commandName} was found.`);
- return;
- }
- try {
- await command.execute(interaction);
- } catch (error) {
- console.error(error);
- if (interaction.replied || interaction.deferred) {
- await interaction.followUp({
- content: 'There was an error while executing this command!',
- ephemeral: true
- });
- } else {
- await interaction.followUp({
- content: 'There was an error while executing this command!',
- ephemeral: true
- });
- }
- }
- } else if (interaction.isButton()) {
- const disabledApprove = new ButtonBuilder()
- .setEmoji('✅')
- .setCustomId('disabledApprove')
- .setLabel('Approve')
- .setStyle(ButtonStyle.Success)
- .setDisabled(true);
- const disabledDeny = new ButtonBuilder()
- .setEmoji('❎')
- .setCustomId('disabledDeny')
- .setLabel('Deny')
- .setStyle(ButtonStyle.Danger)
- .setDisabled(true);
- const disabledRow = new ActionRowBuilder()
- .addComponents(disabledApprove, disabledDeny);
- const allowedIDs = ["908762498331709480", "908763421833584671", "1196511226545574021", "1196486582765617253"];
- if (interaction.customId === 'approve') {
- if (interaction.member.roles.cache.hasAny(...allowedIDs)) {
- const originalEmbed = interaction.message.embeds[0];
- const approvedEmbed = new EmbedBuilder()
- .setColor('#2ecc71') // Change the color to green
- .setTitle('Award Request Approved') // Change the title
- .setDescription('The award request has been approved.') // Change the description
- .setFields(originalEmbed.fields) // Copy the fields from the original embed
- .addFields(
- {name: "Update approved by", value: `<@${interaction.member.id}>`},
- )
- if (interaction.member.roles.cache.hasAny(...allowedIDs)) {
- await interaction.message.edit({
- embeds: [approvedEmbed],
- components: [disabledRow]
- }).catch(console.error);
- let award = await interaction.message.embeds[0].fields[0].value;
- let recipient = await interaction.message.embeds[0].fields[2].value;
- let awarderID = interaction.member.id;
- let awarderNickname = (await interaction.guild.members.fetch(awarderID)).nickname;
- let reason = await interaction.message.embeds[0].fields[3].value;
- let updater = await interaction.message.embeds[0].fields[4].value;
- switch (award) {
- case "Medal of Honor":
- await trello.addCard(
- interaction.message.embeds[0].fields[2].value,
- `Recipient: ${recipient}
- Awarded by: ${awarderNickname}
- Reason: ${reason}
- Approved by: ${updater}
- This was added via an Amethyst Integration.
- `, "64359eb18b396e40d86a50be")
- break
- case "":
- default:
- console.log('nuh uh no award for you');
- }
- }
- await interaction.reply({
- content: "Award successfully approved.",
- ephemeral: true
- })
- } else {
- await interaction.reply({
- content: 'You do not have permission to run this command. Contact <@1071373709157351464> if you think that this is a mistake.',
- ephemeral: true
- });
- }
- } else if (interaction.customId === 'deny') {
- if (interaction.member.roles.cache.hasAny(...allowedIDs)) {
- const modal = new ModalBuilder()
- .setCustomId('denyModal')
- .setTitle('Denial Information')
- const denialReason = new TextInputBuilder()
- .setCustomId('denialReason')
- .setLabel('Why was this award request denied?')
- .setStyle(TextInputStyle.Paragraph)
- .setRequired(true)
- const actionRow1 = new ActionRowBuilder().addComponents(denialReason);
- modal.addComponents(actionRow1);
- const filter = (interaction) => interaction.customId === 'denyModal';
- await interaction.showModal(modal);
- const blah = await interaction.awaitModalSubmit({filter, time: 120_000})
- await blah.reply({
- content: "Award successfully denied.",
- ephemeral: true
- })
- .catch(console.error);
- const denialReasonFr = blah.fields.getTextInputValue('denialReason')
- const originalEmbed = interaction.message.embeds[0];
- const deniedEmbed = new EmbedBuilder()
- .setColor('#d30e0e') // Change the color to red
- .setTitle('Award Denied') // Change the title
- .setDescription('The award request has been denied.') // Change the description
- .setFields(originalEmbed.fields) // Copy the fields from the original embed
- .addFields(
- {name: "Award Denied by", value: `<@${interaction.member.id}>`},
- {name: "Reason for denial", value: `${denialReasonFr}`}
- )
- if (interaction.member.roles.cache.hasAny(...allowedIDs)) {
- await interaction.message.edit({
- embeds: [deniedEmbed],
- components: [disabledRow]
- }).catch(console.error);
- } else {
- await interaction.message.reply({
- content: 'You do not have permission to run this command. Contact <@1071373709157351464> if you think that this is a mistake.',
- ephemeral: true
- });
- }
- } else {
- await interaction.reply({
- content: 'You do not have permission to run this command. Contact <@1071373709157351464> if you think that this is a mistake.',
- ephemeral: true
- });
- }
- } else {
- await interaction.message.reply({
- content: 'You do not have permission to run this command. Contact <@1071373709157351464> if you think that this is a mistake.',
- ephemeral: true
- });
- }
- } else if (interaction.isStringSelectMenu()) {
- // hjandle
- } else if (interaction.isAutocomplete()) {
- const command = interaction.client.commands.get(interaction.commandName);
- if (!command) {
- console.error(`No command matching ${interaction.commandName} was found.`);
- return;
- }
- try {
- await command.autocomplete(interaction);
- } catch (error) {
- console.error(error);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment