const { SlashCommandBuilder, PermissionsBitField } = require('discord.js'); const api = require('../api'); module.exports = { name: 'add-twitchuser', description: 'Admin: add a Twitch username to watch for this server', enabled: true, builder: new SlashCommandBuilder() .setName('add-twitchuser') .setDescription('Add a Twitch username to watch for live notifications') .addStringOption(opt => opt.setName('username').setDescription('Twitch username').setRequired(true)), async execute(interaction) { if (!interaction.member.permissions.has(PermissionsBitField.Flags.Administrator)) { await interaction.reply({ content: 'You must be an administrator to use this command.', flags: 64 }); return; } const username = interaction.options.getString('username').toLowerCase().trim(); try { const success = await api.addTwitchUser(interaction.guildId, username); if (success) { await interaction.reply({ content: `Added ${username} to watch list.`, flags: 64 }); // Refresh cached settings from backend so watcher sees new user immediately try { const settings = await api.getServerSettings(interaction.guildId); const bot = require('..'); if (bot && bot.setGuildSettings) bot.setGuildSettings(interaction.guildId, settings); } catch (_) {} } else { await interaction.reply({ content: 'Failed to add user via backend.', flags: 64 }); } } catch (e) { console.error('Error adding twitch user:', e); await interaction.reply({ content: 'Internal error adding twitch user.', flags: 64 }); } } };