Advertisement
document10

Advanced Discord.JS Polls command

Sep 17th, 2023 (edited)
1,203
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 5.54 KB | Source Code | 1 0
  1. const { SlashCommandBuilder, EmbedBuilder ,CommandInteraction,Client} = require('discord.js');
  2.  
  3. module.exports = {
  4.     data: new SlashCommandBuilder()
  5.         .setName('poll')
  6.         .setDescription('Creates a poll with up to ten options')
  7.         .addStringOption(option => option.setName('title')
  8.             .setDescription('The title of the poll')
  9.             .setRequired(true)
  10.         )
  11.         .addStringOption(option => option.setName('option1')
  12.             .setDescription('First option (required)')
  13.             .setRequired(true)
  14.         )
  15.         .addStringOption(option => option.setName('option2')
  16.             .setDescription('Second option (required)')
  17.             .setRequired(true)
  18.         )
  19.         .addStringOption(option => option.setName('option3')
  20.             .setDescription('Third option')
  21.         )
  22.         .addStringOption(option => option.setName('option4')
  23.             .setDescription('Fourth option')
  24.         )
  25.         .addStringOption(option => option.setName('option5')
  26.             .setDescription('Fifth option')
  27.         )
  28.         .addStringOption(option => option.setName('option6')
  29.             .setDescription('Sixth option')
  30.         )
  31.         .addStringOption(option => option.setName('option7')
  32.             .setDescription('Seventh option')
  33.         )
  34.         .addStringOption(option => option.setName('option8')
  35.             .setDescription('Eighth option')
  36.         )
  37.         .addStringOption(option => option.setName('option9')
  38.             .setDescription('Ninth option')
  39.         )
  40.         .addStringOption(option => option.setName('option10')
  41.             .setDescription('Tenth option')
  42.         )
  43.         .addStringOption(option => option.setName('mode')
  44.             .setDescription('The mode to show options in')
  45.             .addChoices(
  46.                 {
  47.                     name:"Numbers",
  48.                     value:"num"
  49.                 },
  50.                 {
  51.                     name:"Letters",
  52.                     value:"li"
  53.                 },
  54.                 {
  55.                     name:"Circles",
  56.                     value:"cir"
  57.                 },
  58.                 {
  59.                     name:"Squares",
  60.                     value:"sq"
  61.                 },
  62.                 {
  63.                     name:"Hearts",
  64.                     value:"hea"
  65.                 },
  66.                 {
  67.                     name:"Books",
  68.                     value:"book"
  69.                 }
  70.             )
  71.         )
  72.         .addRoleOption(option => option.setName('role')
  73.                 .setDescription('Role to mention when the poll is sent')
  74.                 .setRequired(false)
  75.         )
  76.         ,
  77.     category:'utility',
  78.     /**
  79.      * @param {CommandInteraction} interaction
  80.      */
  81.     async execute(interaction) {
  82.         await interaction.reply({content:'Creating poll,please wait',ephemeral:true})
  83.         //reactions
  84.         const num = ['1️⃣','2️⃣','3️⃣','4️⃣','5️⃣','6️⃣','7️⃣','8️⃣','9️⃣','🔟']
  85.         const li = ['🇦','🇧','🇨','🇩','🇪','🇫','🇬','🇭','🇮','🇯']
  86.         const cir = ['🔴','🟢','🔵','🟡','🟣','🟤','🟠','⚪','⚫','🔘']
  87.         const sq = ['🟥','🟩','🟦','🟨','🟪','🟫','🟧','⬜','⬛','⏹️']
  88.         const hea = ['❤️','💚','💙','💛','💜','🤎','🧡','🤍','🖤','💟']
  89.         const book = ['📕','📗','📘','📒','📔','📙','📓','🔖','🗒️','📚']
  90.         const title = interaction.options.getString('title',true)
  91.         //command options
  92.         const role = interaction.options.getRole('role',false)
  93.         var mention = ""
  94.         if(role) mention = `<@&${role.id}>`
  95.         var params = [interaction.options.getString('option1',true),interaction.options.getString('option2',true)]
  96.         var el = ""
  97.         var mode = interaction.options.getString(`mode`,false) || 'num'
  98.         var desc = ""
  99.         var options = new Map()
  100.         var i;
  101.         for (i = 3; i < 11; i++) {
  102.             el = interaction.options.getString(`option${i}`,false)
  103.             if(el)params.push(el)
  104.         }
  105.         switch (mode) {
  106.             case 'num':
  107.                 params.forEach((p,i) => {
  108.                     options.set(p,num[i])
  109.                 })
  110.                 break;
  111.             case 'li':
  112.                 params.forEach((p,i) => {
  113.                     options.set(p,li[i])
  114.                 })
  115.                 break;
  116.             case 'cir':
  117.                 params.forEach((p,i) => {
  118.                     options.set(p,cir[i])
  119.                 })
  120.                 break;
  121.             case 'sq':
  122.                 params.forEach((p,i) => {
  123.                     options.set(p,sq[i])
  124.                 })
  125.                 break;
  126.             case 'hea':
  127.                 params.forEach((p,i) => {
  128.                     options.set(p,hea[i])
  129.                 })
  130.                 break;
  131.             case 'book':
  132.                 params.forEach((p,i) => {
  133.                     options.set(p,book[i])
  134.                 })
  135.                 break;
  136.             default:
  137.                 break;
  138.         }
  139.         options.forEach((v,k)=>{
  140.             desc += `${v} : ${k}\n`
  141.         })
  142.         const embed = new EmbedBuilder()
  143.             .setTitle(title)
  144.             .setAuthor({name:interaction.user.username,iconURL:interaction.user.displayAvatarURL()})
  145.             .setDescription(desc)
  146.             .setColor('#0000ff')
  147.             .setTimestamp()
  148.         const msg = await interaction.channel.send({content:mention,embeds:[embed]})
  149.         options.forEach(async (v,k)=>{
  150.             await msg.react(v)
  151.         })
  152.     },
  153. };
  154.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement