toowake

top.gg vote command

Aug 14th, 2023
513
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { SlashCommandBuilder, EmbedBuilder} = require("discord.js");
  2. const Key = ""; //your bot token from topgg https://top.gg/bot/YourBotID/webhooks
  3. const BotID = "Your Bot ID";
  4.  
  5. module.exports = {
  6.     data: new SlashCommandBuilder()
  7.         .setName("vote")
  8.         .setDescription("Vote on top.gg")
  9.         .setDMPermission(true),
  10.  
  11.     async execute(interaction, client) {
  12.         const { user } = interaction;
  13.         const response = await fetch(`https://top.gg/api/bots/${BotID}/check?userId=${user.id}`, {
  14.             headers: {
  15.                 'Authorization': Key
  16.             }
  17.         });
  18.  
  19.         const data = await response.json();
  20.  
  21.         const voteEmbed = new EmbedBuilder()
  22.         .setColor("White")
  23.         .setTitle("You voted for us!")
  24.         .setDescription(`Thank you for voting for ${client.user.username}!`)
  25.         .setFooter({ text: "Nexus Votes"});
  26.  
  27.         const embed = new EmbedBuilder()
  28.         .setColor("White")
  29.         .setTitle("Vote for us!")
  30.         .setDescription(`Click [here](https://top.gg/bot/${BotID}/vote) to vote!`)
  31.         .setFooter({ text: "Nexus Votes"});
  32.  
  33.         if (data.voted) {
  34.             await interaction.reply({
  35.                 embeds: [voteEmbed]
  36.             });
  37.         } else {
  38.             const reply = await interaction.reply({
  39.                 embeds: [embed]
  40.             });
  41.  
  42.             const interval = setInterval(async () => {
  43.                 const response = await fetch(`https://top.gg/api/bots/${BotID}/check?userId=${user.id}`, {
  44.                     headers: {
  45.                         'Authorization': Key
  46.                     }
  47.                 });
  48.                 const newData = await response.json();
  49.  
  50.                 if (newData.voted) {
  51.                     clearInterval(interval);
  52.                     await reply.edit({
  53.                         embeds: [voteEmbed]
  54.                     });
  55.                 }
  56.             }, 5000);
  57.         }
  58.     }
  59. };
  60.  
Advertisement
Add Comment
Please, Sign In to add comment