toowake

bro.js

Nov 4th, 2023
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Schema = require("../../Schemas.js/brocount");
  2. const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
  3.  
  4. module.exports = {
  5.     data: new SlashCommandBuilder()
  6.     .setName("bro")
  7.     .setDescription("bro count")
  8.     .addSubcommand(command => command
  9.         .setName("count")
  10.         .setDescription("Bro count")
  11.         .addUserOption(option => option.setName("user").setDescription("The bro you want to get the count from").setRequired(false))
  12.     )
  13.     .addSubcommand(command => command
  14.         .setName("leaderboard")
  15.         .setDescription("Leaderboard bro")
  16.     ),
  17.  
  18.     async execute(interaction, client) {
  19.         const { options, guild } = interaction;
  20.         const sub = options.getSubcommand();
  21.  
  22.         switch (sub) {
  23.             case "count":
  24.                 const target = options.getUser("user") || interaction.user;
  25.                 const dataCount = await Schema.findOne({ User: target.id });
  26.  
  27.                 if (dataCount) {
  28.                     const embed = new MessageEmbed()
  29.                         .setDescription(`${target} has ${dataCount.Count}x said bro`)
  30.                         .setColor("WHITE");
  31.  
  32.                     await interaction.reply({
  33.                         embeds: [embed]
  34.                     });
  35.                 } else {
  36.                     await interaction.reply({
  37.                         content: "This user doesn't have said bro",
  38.                         ephemeral: true
  39.                     });
  40.                 }
  41.                 break;
  42.             case "leaderboard":
  43.                 const data = await Schema.find({}); // Find all data
  44.  
  45.                 data.sort((a, b) => b.Count - a.Count); // Sort by Count in descending order
  46.                 data.splice(10); // Limit to the top 10
  47.  
  48.                 const text = data.map((entry, index) => {
  49.                     const dataUser = client.users.cache.get(entry.User) || "Unknown";
  50.                     return `${index + 1}. ${dataUser} | Count: ${entry.Count}`;
  51.                 }).join("\n");
  52.  
  53.                 const embed = new EmbedBuilder()
  54.                     .setColor("White")
  55.                     .setDescription(text);
  56.  
  57.                 await interaction.reply({ embeds: [embed] });
  58.                 break;
  59.         }
  60.     }
  61. };
Advertisement
Add Comment
Please, Sign In to add comment