Skip to content

Commit

Permalink
Added react command
Browse files Browse the repository at this point in the history
  • Loading branch information
SandwichBtw committed Nov 13, 2023
1 parent 1a8c2a3 commit 4b47efd
Showing 1 changed file with 39 additions and 3 deletions.
42 changes: 39 additions & 3 deletions src/modules/commands/reactCommand.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,49 @@
import { SlashCommandBuilder, type ChatInputCommandInteraction } from "discord.js";
import { SlashCommandBuilder, type ChatInputCommandInteraction, type TextChannel } from "discord.js";
import { type Command } from "../../types/Command";
import type CrystalClient from "../../types/CrystalClient";

module.exports = {
name: 'react',
data: new SlashCommandBuilder()
.setName("react")
.setDescription("React to a message using the bot."),
.setDescription("React to a message using the bot.")
.addChannelOption((option) =>
option
.setName('channel')
.setDescription('The channel you want to react to.')
.setRequired(true))
.addStringOption((option) =>
option
.setName('message_id')
.setDescription('The message you want to react to using a message id.')
.setRequired(true))
.addStringOption((option) =>
option
.setName('emoji')
.setDescription('The emoji 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')

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

void await targetMessage.react(reactEmoji)
void await interaction.reply({
content: "The reaction was successful.",
ephemeral: true
})
} else {
void await interaction.reply({
content: "The reaction failed.",
ephemeral: true
})
}
} catch (error) {
console.error()
}
}
} satisfies Command

0 comments on commit 4b47efd

Please sign in to comment.