Skip to content

Commit

Permalink
create poll bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperGawdzinski committed Sep 21, 2023
1 parent 8046d74 commit df96ba5
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions src/modules/createPoll.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { APIEmbedField, ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';
import {
APIEmbedField,
ChatInputCommandInteraction,
DiscordAPIError,
EmbedBuilder
} from 'discord.js';

const numbers = ['1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣', '6️⃣', '7️⃣', '8️⃣', '9️⃣'];

export const createPoll = async (interaction: ChatInputCommandInteraction) => {
setTimeout(() => interaction.deleteReply(), 10000);
const title = interaction.options.data[0].value as string;
const optionsString = interaction.options.data[1].value as string;
const optionsList = optionsString.split(';');
Expand All @@ -15,13 +21,21 @@ export const createPoll = async (interaction: ChatInputCommandInteraction) => {
return;
}

const message = await channel.send({ embeds: [embed] });
numbersList.forEach(async emoji => {
await message.react(emoji);
});
try {
const message = await channel.send({ embeds: [embed] });
numbersList.forEach(async emoji => {
await message.react(emoji);
});

await interaction.reply('.');
await interaction.deleteReply();
await interaction.reply('.');
await interaction.deleteReply();
} catch (err) {
if (err instanceof DiscordAPIError) {
interaction.reply({
content: `Unable to create a poll: ${err.message}. Code: ${err.code}`
});
}
}
};

const createPollEmbed = (
Expand Down

0 comments on commit df96ba5

Please sign in to comment.