const { SlashCommandBuilder, PermissionsBitField } = require('discord.js'); const fetch = require('node-fetch'); 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 backendBase = process.env.BACKEND_BASE || `http://${process.env.HOST || '127.0.0.1'}:${process.env.PORT || 3002}`; const resp = await fetch(`${backendBase}/api/servers/${interaction.guildId}/twitch-users`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username }) }); if (resp.ok) { await interaction.reply({ content: `Added ${username} to watch list.`, flags: 64 }); } 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 }); } } };