Files
ECS-FullStack/discord-bot/commands/remove-twitchuser.js
2025-10-09 19:24:02 -04:00

37 lines
1.6 KiB
JavaScript

const { SlashCommandBuilder, PermissionsBitField } = require('discord.js');
const api = require('../api');
module.exports = {
name: 'remove-twitchuser',
description: 'Admin: remove a Twitch username from this server watch list',
enabled: true,
builder: new SlashCommandBuilder()
.setName('remove-twitchuser')
.setDescription('Remove a Twitch username from the watch list')
.addStringOption(opt => opt.setName('username').setDescription('Twitch username to remove').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.deleteTwitchUser(interaction.guildId, username);
if (success) {
await interaction.reply({ content: `Removed ${username} from watch list.`, flags: 64 });
// Refresh cached settings from backend
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 remove user via backend.', flags: 64 });
}
} catch (e) {
console.error('Error removing twitch user:', e);
await interaction.reply({ content: 'Internal error removing twitch user.', flags: 64 });
}
}
};