feat: Create Poll and Helper commands

pull/5/head
KieranRobson 2023-10-12 11:23:01 +01:00
parent 4837ac6f29
commit dfa1651695
4 changed files with 3786 additions and 3716 deletions

View File

@ -19,6 +19,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"discord-polls": "^1.1.1",
"discord.js": "14.13.0",
"dotenv": "^16.3.1",
"glob": "^7.2.3",

View File

@ -0,0 +1,73 @@
const { SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
const Polls = require('discord-polls');
module.exports = {
...new SlashCommandBuilder()
.setName('start-poll')
.setDescription('Starts a poll')
.addStringOption((option) =>
option
.setName('title')
.setDescription('The title of the poll.')
.setRequired(true)
)
.addStringOption((option) =>
option
.setName('choices')
.setDescription(
'The choices of the poll. *Separate each choice by a dash (-)*'
)
.setRequired(true)
)
.addIntegerOption((option) =>
option
.setName('duration')
.setDescription('The duration of the poll *Time is in seconds*')
.setRequired(true)
)
.addStringOption((option) =>
option
.setName('color')
.setDescription("The color of the poll's embed. *Hex format: #000000*")
.setRequired(true)
)
.addStringOption((option) =>
option
.setName('emojis')
.setDescription(
'The emojis of the poll. *Separate each emoji by a dash (-)*'
)
.setRequired(true)
)
.addStringOption((option) =>
option
.setName('force-end-emoji')
.setDescription('The emoji to force end the poll.')
.setRequired(true)
)
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator),
run: async (client, interaction) => {
// Get the user input from each option.
const title = interaction.options.getString('title');
const choices = interaction.options.getString('choices');
const duration = interaction.options.getInteger('duration');
const color = interaction.options.getString('color');
const emojis = interaction.options.getString('emojis');
const forceEndEmoji = interaction.options.getString('force-end-emoji');
const choicesArray = choices.split('-').map((choice) => choice.trim()); // Map the choices to an array.
const emojisArray = emojis.split('-').map((emoji) => emoji.trim()); // Map the emojis to an array.
// call the startPoll method
Polls.startPoll(
interaction,
title,
choicesArray,
duration,
color,
emojisArray,
forceEndEmoji
);
},
};

View File

@ -0,0 +1,33 @@
const { SlashCommandBuilder } = require('discord.js');
module.exports = {
...new SlashCommandBuilder()
.setName('hourstoseconds')
.setDescription('Make the poll command easier')
.addIntegerOption((option) =>
option
.setName('hours')
.setDescription('The duration of the poll *Time is in seconds*')
.setRequired(true)
),
/**
*
* @param {Client} client
* @param {CommandInteraction} interaction
* @param {String[]} args
*/
run: async (client, interaction) => {
const hours = interaction.options.getInteger('hours');
const hoursParsed = Number(hours);
const seconds = hoursParsed * 3600;
const secondsParsed = seconds.toString();
interaction.reply({
content: `${hours} hours is ${secondsParsed} seconds`,
ephemeral: true,
});
},
};

7395
yarn.lock

File diff suppressed because it is too large Load Diff