From c163d44895be8d1eaf229d4a3fe8f57afc1e3ed0 Mon Sep 17 00:00:00 2001 From: Taken Date: Sun, 12 Mar 2023 16:40:07 +0100 Subject: [PATCH] Adding apply channel --- events/buttons/guilapply.js | 79 +++++++++++++++++++++++++++++- events/buttons/guildapplycancel.js | 27 ++++++++++ index.js | 3 +- 3 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 events/buttons/guildapplycancel.js diff --git a/events/buttons/guilapply.js b/events/buttons/guilapply.js index a355a25..3079997 100644 --- a/events/buttons/guilapply.js +++ b/events/buttons/guilapply.js @@ -1,3 +1,4 @@ +const { ChannelType, PermissionFlagsBits, ButtonBuilder, ButtonStyle, ActionRowBuilder } = require('discord.js'); const { color } = require('../../options.json'); module.exports = { @@ -13,9 +14,83 @@ module.exports = { if (interaction.customId === 'guildapply') { - await interaction.reply({ content: 'Please wait...', ephemeral: true }); + interaction.guild.channels.create({ + name: `application-${user.username}`, + type: ChannelType.GuildText, + permissionOverwrites: [ + { + id: user.id, + allow: [PermissionFlagsBits.ViewChannel] + }, + { + id: guild.roles.everyone, + deny: [PermissionFlagsBits.ViewChannel] + } + ] + }).then(async channel => { + + await channel.send({ + embeds: [{ + title: 'Guild Application', + description: "Please answer the following questions to apply for the guild.\n" + + "If you wish to cancel your application, please press the button below or type `cancel`.", + color: embedColor, + }], + + components: [ + new ActionRowBuilder().addComponents( + new ButtonBuilder() + .setCustomId('guildapplycancel') + .setLabel('Cancel') + .setStyle(ButtonStyle.Danger) + .setEmoji({ name: '❌' }) + ) + ] + + }); + + const input = await channel.awaitMessages({ + filter: m => m.author.id === user.id, + max: 1, + time: 1000 * 60 + }); + + if (input.size === 0) { + await channel.delete(); + return + } + + if (input.first().content.toLowerCase() !== 'yes') { + await channel.delete(); + return + } + + const question1 = await channel.send("1st") + const answer1 = await channel.awaitMessages({ + filter: m => m.author.id === user.id, + max: 1, + time: 1000 * 60 * 5 + }); + + if (answer1.size === 0) { + await channel.delete(); + return + } + + if (answer1.first().content.toLowerCase() === 'cancel') { + await channel.delete(); + return + } + + const answer1_1 = answer1.first().content + + console.log(answer1_1) + + }); + + await interaction.reply({ content: 'Application channel created', ephemeral: true }); + } - } } \ No newline at end of file diff --git a/events/buttons/guildapplycancel.js b/events/buttons/guildapplycancel.js new file mode 100644 index 0000000..36f554d --- /dev/null +++ b/events/buttons/guildapplycancel.js @@ -0,0 +1,27 @@ +const { color } = require('../../options.json'); + +module.exports = { + name: 'guildapplycancel', + description: 'Guild application cancel button.', + type: 'button', + + async execute(interaction) { + + const user = interaction.user; + const guild = interaction.guild; + const embedColor = Number(color.replace("#", "0x")); + + if (interaction.customId === 'guildapplycancel') { + + const channel = interaction.channel; + + await interaction.reply({ content: 'Application channel will be deleted in 5 seconds', ephemeral: true }); + + setTimeout(async () => { + await channel.delete(); + }, 5000); + + } + + } +} \ No newline at end of file diff --git a/index.js b/index.js index 9ec3ad7..7ead872 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,8 @@ const client = new Client({ ], partials: [ Partials.GuildMember, - Partials.User + Partials.User, + Partials.Message ] });