Skip to content

Commit

Permalink
Added error messages and support for multiple emojis in the react com…
Browse files Browse the repository at this point in the history
…mand
  • Loading branch information
SandwichBtw committed Nov 14, 2023
1 parent e1109d8 commit d067f5e
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions src/modules/commands/reactCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,23 @@ module.exports = {
.setRequired(true))
.addStringOption((option) =>
option
.setName('emoji')
.setDescription('The emoji you want to react with.')
.setName('emojis')
.setDescription('The emoji(s) you want to react with.')
.setRequired(true)),
execute: async function (interaction: ChatInputCommandInteraction, client: CrystalClient) {
const textChannel = interaction.options.getChannel('channel') as TextChannel
const messageId = interaction.options.getString('message_id')
const reactEmoji = interaction.options.getString('emoji')
const emojis = interaction.options.getString('emojis')

try {
if ((reactEmoji !== null) && (messageId !== null)) {
const targetMessage = await textChannel.messages.fetch(messageId);
if ((emojis !== null) && (messageId !== null)) {
const targetMessage = await textChannel.messages.fetch(messageId)
const emojiArray = emojis.split(' ')

for (const emoji of emojiArray) {
void await targetMessage.react(emoji.trim())
}

void await targetMessage.react(reactEmoji)
void await interaction.reply({
content: "The reaction was successful.",
ephemeral: true
Expand All @@ -42,8 +46,28 @@ module.exports = {
ephemeral: true
})
}
} catch (error) {
console.error(error)
} catch (error: any) {
switch (true) {
case error.message.includes('Unknown Message'):
void await interaction.reply({
content: "The reaction failed: Invalid message id.",
ephemeral: true
})
break
case error.message.includes('Unknown Emoji'):
void await interaction.reply({
content: "The reaction failed: Invalid emoji(s).",
ephemeral: true
})
break
default:
void await interaction.reply({
content: "The reaction failed.",
ephemeral: true
})

console.error(error)
}
}
}
} satisfies Command

0 comments on commit d067f5e

Please sign in to comment.