task command work

This commit is contained in:
2025-11-11 13:34:35 -05:00
parent 898c8cd2e6
commit 1bb204883c
3 changed files with 41 additions and 8 deletions

View File

@@ -1,10 +1,32 @@
const { SlashCommandBuilder } = require('discord.js');
const torn = require('../../torn.js');
const config = require('../../config.json');
const state = require('../../state.json');
module.exports = {
data: new SlashCommandBuilder()
.setName('task')
.setDescription('Execute a task.'),
.setDescription('Execute a task.')
.addStringOption(option =>
option.setName('name')
.setDescription('The name of the task to execute.')
.setRequired(true)),
async execute(interaction) {
await interaction.reply('todo');
const taskName = interaction.options.getString('name');
const task = interaction.client.tasks[taskName];
if (!task) {
await interaction.reply({ content: `Task "${taskName}" not found.`, ephemeral: true });
return;
}
try {
await interaction.reply({ content: `Executing task "${taskName}"...`, ephemeral: true });
await task(interaction.client, torn, config, state);
await interaction.followUp({ content: `Task "${taskName}" executed successfully.`, ephemeral: true });
} catch (error) {
console.error(error);
await interaction.followUp({ content: `There was an error while executing task "${taskName}"!`, ephemeral: true });
}
},
};