Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add: react command #96

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions commands/react.command.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const { SlashCommandBuilder } = require('@discordjs/builders');
const { embedError } = require('../modules/utility');

const KETUA_KELAS_ID = process.env.ROLE_KETUA;

exports.command = new SlashCommandBuilder()
.setName('react')
.setDescription('React to a message!')
.addStringOption((option) =>
option.setName('message-id').setDescription('The message you want to react').setRequired(true),
)
.addStringOption((option) =>
option.setName('emoji').setDescription('The emoji you want to react').setRequired(true),
);

exports.permissions = [
{
id: KETUA_KELAS_ID,
type: 'ROLE',
permission: true,
},
];

exports.execute = async (interaction) => {
try {
await interaction.deferReply({ ephemeral: true, fetchReply: true });

const messageId = interaction.options.getString('message-id');
const emojiOptions = interaction.options.getString('emoji');
const message = await interaction.channel.messages.fetch(messageId);

const emojis = emojiOptions.split(' ');
for (const emoji of emojis) {
await message.react(emoji);
}

return interaction.editReply({ content: 'Reacted!' });
} catch (error) {
console.error(error);
let errorMessage = error.message ?? 'Something went wrong!';

// Reference: https://discord.com/developers/docs/topics/opcodes-and-status-codes#:~:text=Unknown%20member-,10008,-Unknown%20message
if (error.code === 10008) {
errorMessage = 'Message not found!\nMake sure you are on the same channel with the message!';
}

const errorEmbed = embedError(errorMessage);
return interaction.editReply({ embeds: [errorEmbed], ephemeral: true });
}
};
Loading