Skip to content

Commit 1574e1f

Browse files
Merge pull request #54 from ksiuwr/53-bot-crashing-when-sending-to-channel-without-permission
create poll bug fixed
2 parents 8046d74 + df96ba5 commit 1574e1f

File tree

1 file changed

+21
-7
lines changed

1 file changed

+21
-7
lines changed

src/modules/createPoll.ts

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
import { APIEmbedField, ChatInputCommandInteraction, EmbedBuilder } from 'discord.js';
1+
import {
2+
APIEmbedField,
3+
ChatInputCommandInteraction,
4+
DiscordAPIError,
5+
EmbedBuilder
6+
} from 'discord.js';
27

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

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

18-
const message = await channel.send({ embeds: [embed] });
19-
numbersList.forEach(async emoji => {
20-
await message.react(emoji);
21-
});
24+
try {
25+
const message = await channel.send({ embeds: [embed] });
26+
numbersList.forEach(async emoji => {
27+
await message.react(emoji);
28+
});
2229

23-
await interaction.reply('.');
24-
await interaction.deleteReply();
30+
await interaction.reply('.');
31+
await interaction.deleteReply();
32+
} catch (err) {
33+
if (err instanceof DiscordAPIError) {
34+
interaction.reply({
35+
content: `Unable to create a poll: ${err.message}. Code: ${err.code}`
36+
});
37+
}
38+
}
2539
};
2640

2741
const createPollEmbed = (

0 commit comments

Comments
 (0)