toowake

card.js

Sep 17th, 2023
552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
  2. const Schema = require("../../Schemas.js/Leveling/cardSchema");
  3. /*
  4.     barColor: String,
  5.     rankColor: String,
  6.     levelColor: String,
  7. */
  8. const disabled = require("../../Schemas.js/Panel/Systems/xp");
  9.  
  10. module.exports = {
  11.     data: new SlashCommandBuilder()
  12.     .setName("card")
  13.     .setDescription("Edit the rank card")
  14.     .addSubcommand(command => command.setName("reset").setDescription("reset the rank card to default"))
  15.     .addSubcommand(command => command.setName("bar-track-color").setDescription("Edit the bar color of your default card image").addStringOption(option => option.setName("color").setDescription("Please set the hex code of your color here").setMinLength(7).setMaxLength(7).setRequired(true)))
  16.     .addSubcommand(command => command.setName("rank-color").setDescription("Edit the bar color of your default card image").addStringOption(option => option.setName("color").setDescription("Please set the hex code of your color here").setMinLength(7).setMaxLength(7).setRequired(true)))
  17.     .addSubcommand(command => command.setName("level-color").setDescription("Edit the bar color of your default card image").addStringOption(option => option.setName("color").setDescription("Please set the hex code of your color here").setMinLength(7).setMaxLength(7).setRequired(true)))    
  18.     .addSubcommand(command => command.setName("track-color").setDescription("Edit the bar color of your default card image").addStringOption(option => option.setName("color").setDescription("Please set the hex code of your color here").setMinLength(7).setMaxLength(7).setRequired(true))),
  19.     async execute (interaction, client) {
  20.         const {options, user, guild} = interaction;
  21.         const data = await Schema.findOne({ User: user.id, Guild: guild.id});
  22.         const sub = options.getSubcommand();
  23.  
  24.         const DISABLED = await disabled.findOne({ Guild: guild.id});
  25.  
  26.         if (DISABLED) {
  27.             await interaction.reply({
  28.                 content: "❌ Command has been disabled in this server!",
  29.                 ephemeral: true
  30.             })
  31.         }
  32.  
  33.         if (!data) {
  34.             return await interaction.reply({
  35.                 content: "You dont have data to change!",
  36.                 ephemeral: true
  37.             })
  38.         }
  39.  
  40.         switch (sub) {
  41.             case "bar-track-color":
  42.                 const barColor = options.getString("color");
  43.                
  44.                 if (!barColor.startsWith("#")) {
  45.                     await interaction.reply({ content: "Please use a valid [Hex code](https://color-hex.com/)!", ephemeral: true})
  46.                 } else {
  47.                     await Schema.updateOne({
  48.                         User: user.id,
  49.                         Guild: guild.id,
  50.                         barTrackColor: barColor,
  51.                     });
  52.  
  53.                     const barEmbed = new EmbedBuilder()
  54.                     .setTitle("Color changed")
  55.                     .setDescription(`Bar color has been set to ${barColor}`)
  56.  
  57.                     return await interaction.reply({ embeds: [barEmbed] });
  58.                 }
  59.             break;
  60.            
  61.             case "bar-color":
  62.                 const bartColor = options.getString("color");
  63.                
  64.                 if (!bartColor.startsWith("#")) {
  65.                     await interaction.reply({ content: "Please use a valid [Hex code](https://color-hex.com/)!", ephemeral: true})
  66.                 } else {
  67.                     await Schema.updateOne({
  68.                         User: user.id,
  69.                         Guild: guild.id,
  70.                         barColor: bartColor,
  71.                     });
  72.  
  73.                     const barEmbed = new EmbedBuilder()
  74.                     .setTitle("Color changed")
  75.                     .setDescription(`Bar color has been set to ${bartColor}`)
  76.  
  77.                     return await interaction.reply({ embeds: [barEmbed] });
  78.                 }
  79.             break;
  80.             case "rank-color":
  81.                 const rankColor = options.getString("color");
  82.                
  83.                 if (!rankColor.startsWith("#")) {
  84.                     await interaction.reply({ content: "Please use a valid [Hex code](https://color-hex.com/)!", ephemeral: true})
  85.                 } else {
  86.                     await Schema.updateOne({
  87.                         User: user.id,
  88.                         Guild: guild.id,
  89.                         rankColor: rankColor,
  90.                     });
  91.  
  92.                     const barEmbed = new EmbedBuilder()
  93.                     .setTitle("Color changed")
  94.                     .setDescription(`Rank color has been set to ${rankColor}`)
  95.  
  96.                     return await interaction.reply({ embeds: [barEmbed] });
  97.                 }
  98.             break;
  99.             case "level-color":
  100.                 const levelColor = options.getString("color");
  101.                
  102.                 if (!levelColor.startsWith("#")) {
  103.                     await interaction.reply({ content: "Please use a valid [Hex code](https://color-hex.com/)!", ephemeral: true})
  104.                 } else {
  105.                     await Schema.updateOne({
  106.                         User: user.id,
  107.                         Guild: guild.id,
  108.                         levelColor: levelColor,
  109.                     });
  110.  
  111.                     const barEmbed = new EmbedBuilder()
  112.                     .setTitle("Color changed")
  113.                     .setDescription(`Level color has been set to ${levelColor}`)
  114.  
  115.                     return await interaction.reply({ embeds: [barEmbed] });
  116.                 }
  117.             break;
  118.             case "reset":
  119.                 await Schema.deleteMany({
  120.                     Guild: guild.id,
  121.                     User: user.id
  122.                 });
  123.  
  124.                 await interaction.reply({
  125.                     content: "Your card has been resetted successfull!",
  126.                     ephemeral: true
  127.                 });
  128.             break;
  129.         }
  130.     }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment