tournament-helper-bot/commands/events/delete_event.js

31 lines
1.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const { SlashCommandBuilder, MessageFlags, EmbedBuilder } = require('discord.js');
const { Tournament } = require("../../data_objects/tournament.js");
const { tetrioRanks } = require("../../data_objects/tetrio_ranks.js");
const { updateTournamentsJSON } = require("../../utils.js");
const { tournaments, blacklist, whitelist } = require("../../index.js");
module.exports = {
data: new SlashCommandBuilder()
.setName('delete_event')
.setDescription('Удалить событие и всё связанное с ним')
.addStringOption(option =>
option.setName('key')
.setDescription('Время создания события')
.setRequired(true)),
async execute(interaction) {
const t = tournaments.get(interaction.options.getString('key'));
try{
await interaction.guild.roles.delete(t.participant_role, 'Информация о турнире удалена');
await interaction.guild.roles.delete(t.checked_in_role, 'Информация о турнире удалена');
const msg_channel = await interaction.client.channels.fetch(t.channelID);
const msg = await msg_channel.messages.fetch(t.messageID);
msg.delete();
interaction.reply({ content: `Готово`, flags: MessageFlags.Ephemeral });
}catch(e){
interaction.reply({ content: `Не всё прошло гладко, но турнир из бота был удален\n\`${e}\``, flags: MessageFlags.Ephemeral });
}
tournaments.delete(interaction.options.getString('key'));
updateTournamentsJSON();
},
};