task command work
This commit is contained in:
@@ -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 });
|
||||
}
|
||||
},
|
||||
};
|
||||
@@ -1,10 +1,22 @@
|
||||
const { SlashCommandBuilder } = require('discord.js');
|
||||
const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
|
||||
|
||||
module.exports = {
|
||||
data: new SlashCommandBuilder()
|
||||
.setName('tasks')
|
||||
.setDescription('List tasks'),
|
||||
.setDescription('Lists all available tasks.'),
|
||||
async execute(interaction) {
|
||||
await interaction.reply('todo');
|
||||
const taskNames = Object.keys(interaction.client.tasks);
|
||||
|
||||
if (taskNames.length === 0) {
|
||||
await interaction.reply({ content: 'No tasks found.', ephemeral: true });
|
||||
return;
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setColor(0xBB99FF)
|
||||
.setTitle('Available Tasks')
|
||||
.setDescription(taskNames.map(name => `- ${name}`).join('\n'));
|
||||
|
||||
await interaction.reply({ embeds: [embed], ephemeral: true });
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user