toowake

command

May 9th, 2023 (edited)
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const {SlashCommandBuilder, EmbedBuilder, PermissionFlagsBits, ChannelType} = require("discord.js");
  2. const setupSchema = require("../../Schemas.js/loginSchema");
  3. const mailSchema = require("../../Schemas.js/loginSchemaMail");
  4.  
  5. module.exports = {
  6.     data: new SlashCommandBuilder()
  7.     .setName("login")
  8.     .setDescription("Login System")
  9.     .setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers)
  10.     .addSubcommand(command => command
  11.         .setName("setup")
  12.         .setDescription("setup the login/logout system")
  13.         .addChannelOption(option => option
  14.             .setName("channel")
  15.             .setDescription("The channel for the login/logout message")
  16.             .setRequired(true)
  17.             .addChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement)
  18.         )
  19.     )
  20.     .addSubcommand(command => command
  21.         .setName("disable")
  22.         .setDescription("Disable the system")
  23.     )
  24.     .addSubcommand(command => command
  25.         .setName("logout")
  26.         .setDescription("logout at your server")
  27.         .addStringOption(option => option
  28.             .setName("reason")
  29.             .setDescription("the reason for logout")
  30.             .setRequired(false)
  31.         )
  32.     )
  33.     .addSubcommand(command => command
  34.         .setName("login")
  35.         .setDescription("login at your server")
  36.     )
  37.     ,
  38.  
  39.     async execute (interaction, client) {
  40.         const sub = interaction.options.getSubcommand();
  41.  
  42.         const data = await setupSchema.findOne({Guild: interaction.guild.id});
  43.         const data2 = await mailSchema.findOne({User: interaction.user.id, Guild: interaction.guild.id});
  44.  
  45.         switch (sub) {
  46.             case "setup":
  47.                 const channel = interaction.options.getChannel("channel")
  48.                 const embed = new EmbedBuilder()
  49.                 .setTitle("Login System")
  50.                 .setDescription(`The system has been setup in <#${channel.id}>!`)
  51.                 .setColor("Blurple")
  52.                 .setTimestamp()
  53.  
  54.                 if (data) {
  55.                     await interaction.reply({
  56.                         content: "The system has already been setup",
  57.                         ephemeral: true
  58.                     })
  59.                 } else {
  60.                     setupSchema.create({
  61.                         Guild: interaction.guild.id,
  62.                         Channel: channel.id
  63.                     })
  64.  
  65.                     await interaction.reply({ embeds: [embed] });
  66.                 }
  67.             break;
  68.  
  69.             case "disable":
  70.                 if (data) {
  71.                     await setupSchema.deleteMany();
  72.  
  73.                     await interaction.reply({ content: "The logging system has been deleted!", ephemeral: true})
  74.                 } else {
  75.                     await interaction.reply({ content: "I cant find a logging System here...."})
  76.                 }
  77.             break;
  78.  
  79.             case "login":
  80.                 const embed2 = new EmbedBuilder()
  81.                 .setTitle("Logging System")
  82.                 .setColor("Green")
  83.                 .addFields(
  84.                     {name: "Status:", value: "logged in", inline: true},
  85.                     {name: "User:", value: `<@${interaction.user.id}>`}
  86.                 )
  87.                 .setTimestamp()
  88.  
  89.                 if (!data2) {
  90.                     await interaction.reply({content: "You have already been logged in!"})
  91.                 };
  92.  
  93.                 if (data2) {
  94.                     await mailSchema.deleteMany({ Guild: interaction.guild.id, User: interaction.user.id});
  95.  
  96.                     await interaction.reply({embeds: [embed2], ephemeral: true});
  97.  
  98.                     const channel2 = data.Channel;
  99.                     const channel2x = client.channels.cache.get(`${channel2}`)
  100.  
  101.                     await channel2x.send({ embeds: [embed2]});
  102.                 };
  103.  
  104.                 if (!data) {
  105.                     await interaction.reply({ content: "There is no logging system here"});
  106.                 };
  107.             break;
  108.  
  109.             case "logout":
  110.                 const message = interaction.options.getString("reason") || "no reason given";
  111.  
  112.                 const embed3 = new EmbedBuilder()
  113.                 .setTitle("Logging System")
  114.                 .setColor("Red")
  115.                 .addFields(
  116.                     {name: "Status:", value: "logged out", inline: true},
  117.                     {name: "User:", value: `<@${interaction.user.id}>`},
  118.                     {name: "Reason:", value: `${message}`}
  119.                 )
  120.                 .setTimestamp()
  121.  
  122.                 if (data2) {
  123.                     await interaction.reply({content: "You have already been logged out!"})
  124.                 };
  125.                  
  126.                 if (!data2) {
  127.                     await mailSchema.create({
  128.                         Guild: interaction.guild.id,
  129.                         User: interaction.user.id,
  130.                         Message: `${message}`
  131.                 });
  132.  
  133.                     await interaction.reply({embeds: [embed3], ephemeral: true});
  134.  
  135.                     const channel3 = data.Channel;
  136.                     const channel3x = client.channels.cache.get(`${channel3}`)
  137.  
  138.                     await channel3x.send({ embeds: [embed3]});
  139.                 };
  140.  
  141.                 if (!data) {
  142.                     await interaction.reply({ content: "There is no logging system here"});
  143.                 };
  144.             break;
  145.         }
  146.     }
  147. }
Advertisement
Add Comment
Please, Sign In to add comment