From 1ef53e8dd01ae8553926ebe380232c57ae892d1e Mon Sep 17 00:00:00 2001 From: Nemo Date: Sun, 14 Nov 2021 02:18:36 +0100 Subject: [PATCH] =?UTF-8?q?ajout=20de=20la=20fonctionnalit=C3=A9=20de=20so?= =?UTF-8?q?ndage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- commands/poll.js | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/commands/poll.js b/commands/poll.js index 7cf4454..d0bfc10 100644 --- a/commands/poll.js +++ b/commands/poll.js @@ -1,19 +1,45 @@ -const { SlashCommandBuilder, codeBlock } = require('@discordjs/builders'); -const { userMention } = require("@discordjs/builders"); +const { SlashCommandBuilder, bold } = require('@discordjs/builders'); +const { MessageEmbed } = require('discord.js'); -module.exports = { - data: new SlashCommandBuilder() + 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 textReply = ""; - console.log(question); - await interaction.reply('Sondage'); + 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++; + }) }, };