const { SlashCommandBuilder } = require('discord.js'); const { User } = require('../database'); const config = require('../config.json'); function hasRole(interaction, roleId) { return interaction.member.roles.cache.has(roleId); } module.exports = { data: new SlashCommandBuilder() .setName('crime-log-link') .setDescription('Link your crime log forum channel to your user profile (LML only)') .addStringOption(opt => opt.setName('forum_channel').setDescription('Forum channel ID').setRequired(true)), async execute(interaction) { if (!hasRole(interaction, config.LML_ROLE)) return interaction.reply({ content: 'You need the LML role to use this command.', ephemeral: true }); const forumChannel = interaction.options.getString('forum_channel'); if (forumChannel !== config.crime_forum) return interaction.reply({ content: 'Invalid forum channel ID.', ephemeral: true }); let user = await User.findOne({ where: { userId: interaction.user.id } }); if (!user) user = await User.create({ userId: interaction.user.id }); user.crimeLogChannel = forumChannel; await user.save(); return interaction.reply({ content: 'Your crime log forum has been linked!', ephemeral: true }); } };