auth-bot

Discord Bot to verify user, allowing server owner to recover server by pulling back members
git clone https://codeberg.org/night0721/auth-bot
Log | Files | Refs | README | LICENSE

setup.js (3290B)


      1 const {
      2   Client,
      3   CommandInteraction,
      4   EmbedBuilder,
      5   ActionRowBuilder,
      6   ButtonBuilder,
      7   ButtonStyle,
      8 } = require("discord.js");
      9 const config = require("../../../config");
     10 const server = require("../../../models/server");
     11 module.exports = {
     12   name: "setup",
     13   description: "Verify Embed",
     14   options: [
     15     {
     16       type: 7,
     17       name: "channel",
     18       description: "Channel to send verify embed",
     19       required: true,
     20     },
     21     {
     22       type: 8,
     23       name: "role",
     24       description: "Role to give when verified",
     25       required: true,
     26     },
     27   ],
     28   /**
     29    *
     30    * @param {Client} client
     31    * @param {CommandInteraction} interaction
     32    * @param {String[]} args
     33    */
     34   run: async (client, interaction, args) => {
     35     const data = await server.findOne({ id: interaction.guild.id });
     36     if (data) {
     37       return interaction.editReply({
     38         ephemeral: true,
     39         embeds: [
     40           new EmbedBuilder()
     41             .setTitle("Error!")
     42             .setDescription("You have already setup the server!")
     43             .setColor("#02023a"),
     44         ],
     45       });
     46     }
     47 
     48     let code = generateCode();
     49     await interaction.editReply({
     50       ephemeral: true,
     51       embeds: [
     52         new EmbedBuilder()
     53           .setTitle("Setting up your server...")
     54           .setDescription(
     55             `Code: \`${code}\`\n**Make sure not to share it and store it, it is essential to pull back members**`
     56           )
     57           .setColor("#02023a"),
     58       ],
     59     });
     60     const members = Array.from(
     61       (await interaction.guild.members.fetch()).filter(e => !e.user.bot).keys()
     62     );
     63     await new server({
     64       id: interaction.guild.id,
     65       code,
     66       members,
     67       role: args[1],
     68     }).save();
     69     try {
     70       interaction.guild.channels.cache.get(args[0]).send({
     71         embeds: [
     72           new EmbedBuilder()
     73             .setTitle("Verify yourself in this server")
     74             .setDescription(
     75               "Verifying allows server admins to add you to new server in case it got deleted. You can deauthorize the bot in 'Authorized Apps', but we will not be able to add you to backup servers."
     76             )
     77             .setFooter({
     78               text: "By verifying you agree to let the owner make you join future servers",
     79             })
     80             .setColor("#02023a"),
     81         ],
     82         components: [
     83           new ActionRowBuilder().addComponents(
     84             new ButtonBuilder()
     85               .setLabel("Verify here")
     86               .setURL(
     87                 `https://discord.com/oauth2/authorize?response_type=code&redirect_uri=${encodeURIComponent(
     88                   process.env.CALLBACK_URL
     89                 )}&scope=${encodeURIComponent(
     90                   config.scope.join(" ")
     91                 )}&client_id=${process.env.CLIENT_ID}`
     92               )
     93               .setStyle(ButtonStyle.Link)
     94           ),
     95         ],
     96       });
     97     } catch (e) {}
     98   },
     99 };
    100 
    101 function generateCode() {
    102   let result = "";
    103   const characters =
    104     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    105   const charactersLength = characters.length;
    106   for (let i = 0; i < 50; i++) {
    107     result += characters.charAt(Math.floor(Math.random() * charactersLength));
    108   }
    109   return result;
    110 }