Billy/commands/poll.js

46 lines
1.6 KiB
JavaScript

const { SlashCommandBuilder, bold } = require('@discordjs/builders');
const { MessageEmbed } = require('discord.js');
const command = new SlashCommandBuilder()
.setName('poll')
.setDescription('Sondage')
.addStringOption(option =>
option.setName('question')
.setDescription('La question que vous souhaitez poser aux autres utilisateurs')
.setRequired(true)
);
for (let i = 0; i<20;i++){
var index = i + 1;
command.addStringOption(option =>
option.setName('réponse' + index )
.setDescription('La réponse ' + index)
.setRequired(false)
);
}
module.exports = {
data: command,
async execute(interaction) {
const question = interaction.options.get('question').value;
const answers = interaction.options.data.slice(1, interaction.options.data.length);
const reactions = ['🇦', '🇧', '🇨', '🇩', '🇪', '🇫', '🇬', '🇭', '🇮', '🇯', '🇰', '🇱', '🇲', '🇳', '🇴', '🇵', '🇶', '🇷', '🇸', '🇹', '🇺', '🇻', '🇼', '🇽', '🇾', '🇿' ];
var desc = "";
var j = 0;
answers.forEach(element => {
desc += reactions[j] + ' : ' + element.value + '\n';
j++;
});
const embed = new MessageEmbed()
.setDescription(desc)
.setColor('RANDOM')
var message = await interaction.reply({content : '📊 ' + bold(question), embeds: [embed], fetchReply: true});
j = 0;
answers.forEach(element=>{
message.react(reactions[j]);
j++;
})
},
};