-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
} | ||
}; |