DiscordJS-Example/commands/admin/self_roles/context/register.js

38 lines
1.0 KiB
JavaScript
Raw Normal View History

2024-02-11 01:04:12 +00:00
import {
ApplicationCommandType,
ContextMenuCommandBuilder,
PermissionFlagsBits,
ContextMenuCommandInteraction
} from 'discord.js';
2024-02-06 18:12:34 +00:00
import { Message } from '../../../../database.js';
2024-02-05 20:27:04 +00:00
export const data = new ContextMenuCommandBuilder()
.setDMPermission(false)
.setName('Register self roles')
.setType(ApplicationCommandType.Message)
.setDefaultMemberPermissions(PermissionFlagsBits.ManageRoles);
2024-02-11 01:04:12 +00:00
/** @param {ContextMenuCommandInteraction} interaction */
2024-02-05 20:27:04 +00:00
export async function execute(interaction) {
const id = interaction.targetMessage.id;
try {
// Create database entry
await Message.create({ id });
// Reply successfully to acknowledge command
await interaction.reply({
content: `Successfully saved data from message! Add roles to it with reference ID '${id}'.`,
2024-02-06 15:18:06 +00:00
ephemeral: true
2024-02-05 20:27:04 +00:00
});
console.info(`[INFO] New self roles on message with ID: '${id}'.`);
} catch (error) {
console.error(error);
// Reply failed to acknowledge command
await interaction.reply({
content: 'Failed to save data from message!',
2024-02-06 15:18:06 +00:00
ephemeral: true
2024-02-05 20:27:04 +00:00
});
}
}