import { CommandInteraction, TextChannel, } from 'discord.js'; import {Command} from '../../classes/command'; import {logger} from '../../logger' import {getContest, clearContest} from '../../functions/database'; function isTextChannel(data: unknown): data is TextChannel{ return (data as TextChannel).name !== undefined; } class Clear extends Command{ get name(){return "clear";} get description(){return "clear contest.";} async execute(interaction: CommandInteraction): Promise{ if(!isTextChannel(interaction.channel)){ await interaction.reply({ content: `Channel name doesn't exist!` }); logger.error(`Channel name doesn't exist`); return; } const contestName = interaction.channel.name; const channelId = interaction.channel.id; const contest = await getContest(contestName); if(contest === null){ await interaction.reply({ content: `The contest in this channel didn't start!` }); logger.error(`Contest ${contestName} didn't start`); return; } await clearContest(channelId); await interaction.reply({content: `Clear ${contestName} complete.`}); logger.log(`Command: clear ${contestName}/${channelId}`); } }; export const command = new Clear();