Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const fs = require('fs');
- const path = require('path');
- const { Client, GatewayIntentBits, Collection, EmbedBuilder, REST, Routes, SlashCommandBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle, StringSelectMenuBuilder, TextInputBuilder, ModalBuilder, TextInputStyle } = require('discord.js');
- const { token, clientId, guildId } = require('./config.json'); // Import the token from config.json
- const client = new Client({
- intents: [
- GatewayIntentBits.Guilds,
- GatewayIntentBits.GuildMessages,
- GatewayIntentBits.MessageContent,
- GatewayIntentBits.GuildMessageReactions
- ]
- });
- const flightPlansPath = path.join(__dirname, './data/flightPlans.json');
- const embedMessageIdsPath = path.join(__dirname, './data/embedMessageIds.json');
- // Ensure flightPlans.json and embedMessageIds.json exist and are initialized properly
- if (!fs.existsSync(flightPlansPath)) {
- fs.writeFileSync(flightPlansPath, JSON.stringify({}));
- }
- if (!fs.existsSync(embedMessageIdsPath)) {
- fs.writeFileSync(embedMessageIdsPath, JSON.stringify({}));
- }
- let embedMessageIds = JSON.parse(fs.readFileSync(embedMessageIdsPath, 'utf-8'));
- const logChannelId = '1255176551063097489'; // Replace with your log channel ID
- const roleID = '1241813787280015361'; // Role ID that can use the commands
- client.commands = new Collection();
- const airportChannels = {
- 'MDPC': '1255157149194125342',
- 'MDAB': '1255157175442083900',
- 'MDST': '1255157186552922142',
- 'EGKK': '1255157200511303771',
- 'EFKT': '1255157212616065166',
- 'LYTV': '1255157226000093205',
- 'LEMH': '1255157238620754001',
- 'GCLP': '1255157255637303381',
- 'EGHI': '1255157273140133940'
- };
- Object.keys(airportChannels).forEach(airport => {
- client.commands.set(`embed${airport.toLowerCase()}`, {
- name: `embed${airport.toLowerCase()}`,
- description: `Shows filed flight plans for ${airport}`,
- execute: async (message) => {
- try {
- console.log(`Executing command /embed${airport.toLowerCase()}`);
- // Load flight plans from file
- let flightPlans = JSON.parse(fs.readFileSync(flightPlansPath, 'utf-8'));
- embedMessageIds = JSON.parse(fs.readFileSync(embedMessageIdsPath, 'utf-8'));
- console.log(`Loaded flight plans: ${JSON.stringify(flightPlans)}`);
- // Ensure the airport is initialized in flightPlans
- if (!flightPlans[airport]) {
- flightPlans[airport] = { departures: [], arrivals: [] };
- console.log(`Initialized flight plans for ${airport}`);
- }
- const departures = flightPlans[airport].departures.map(plan => `${plan.callsign} | ${plan.destination} | ${plan.squawk || 'No squawk'}`).join('\n') || 'No departures';
- const arrivals = flightPlans[airport].arrivals.map(plan => `${plan.callsign} | ${plan.departedFrom} | ${plan.squawk || 'No squawk'}`).join('\n') || 'No arrivals';
- const embed = new EmbedBuilder()
- .setColor('#88ebff')
- .setTitle(`${airport} | Filed Flight Plans | Departing & Arriving`)
- .addFields(
- { name: '**Departures**', value: departures },
- { name: '**Arrivals**', value: arrivals }
- );
- const row = new ActionRowBuilder()
- .addComponents(
- new ButtonBuilder()
- .setCustomId(`remove_aircraft_${airport.toLowerCase()}`)
- .setLabel('Remove Aircraft')
- .setStyle(ButtonStyle.Danger),
- new ButtonBuilder()
- .setCustomId(`get_details_${airport.toLowerCase()}`)
- .setLabel('Get Details')
- .setStyle(ButtonStyle.Secondary),
- new ButtonBuilder()
- .setCustomId(`assign_squawk_${airport.toLowerCase()}`)
- .setLabel('Assign Squawk')
- .setStyle(ButtonStyle.Primary)
- );
- console.log(`Sending embed for ${airport}`);
- const embedMessage = await message.channel.send({ embeds: [embed], components: [row] });
- embedMessageIds[airport] = embedMessage.id;
- fs.writeFileSync(embedMessageIdsPath, JSON.stringify(embedMessageIds, null, 2));
- console.log(`Embed sent for ${airport} with message ID: ${embedMessage.id}`);
- const logChannel = message.guild.channels.cache.get(logChannelId);
- if (logChannel) {
- const logEmbed = new EmbedBuilder()
- .setColor('#88ebff')
- .setTitle('Command Log')
- .addFields(
- { name: 'User', value: message.author.tag },
- { name: 'Command', value: message.content },
- { name: 'Time', value: new Date().toISOString() }
- );
- await logChannel.send({ embeds: [logEmbed] });
- console.log(`Log sent for ${airport} command`);
- }
- } catch (error) {
- console.error(`Error in command /embed${airport.toLowerCase()}:`, error);
- await message.reply('There was an error while executing this command!');
- }
- }
- });
- });
- client.commands.set('fileflightplan', {
- name: 'fileflightplan',
- description: 'Files a flight plan',
- execute: async (message, args) => {
- try {
- console.log('Executing command /fileflightplan');
- if (args.length < 6) {
- return message.reply('Please provide a callsign, departure, arrival, aircraft type, IFR/VFR, and CRZ FL.');
- }
- const crzFl = args.pop().toUpperCase();
- const ifrVfr = args.pop().toUpperCase();
- const aircraftType = args.pop().toUpperCase();
- const arrival = args.pop().toUpperCase();
- const departure = args.pop().toUpperCase();
- const callsign = args.join(' ').toUpperCase();
- let flightPlans = JSON.parse(fs.readFileSync(flightPlansPath, 'utf-8'));
- embedMessageIds = JSON.parse(fs.readFileSync(embedMessageIdsPath, 'utf-8'));
- if (!flightPlans[departure]) {
- flightPlans[departure] = { departures: [], arrivals: [] };
- }
- if (!flightPlans[arrival]) {
- flightPlans[arrival] = { departures: [], arrivals: [] };
- }
- flightPlans[departure].departures.push({ callsign, destination: arrival, aircraftType, ifrVfr, crzFl });
- flightPlans[arrival].arrivals.push({ callsign, departedFrom: departure, aircraftType, ifrVfr, crzFl });
- fs.writeFileSync(flightPlansPath, JSON.stringify(flightPlans, null, 2));
- message.reply(`Filed flight plan for ${callsign} from ${departure} to ${arrival}.`);
- console.log(`Filed flight plan for ${callsign} from ${departure} to ${arrival}`);
- const logChannel = message.guild.channels.cache.get(logChannelId);
- if (logChannel) {
- const logEmbed = new EmbedBuilder()
- .setColor('#88ebff')
- .setTitle('Flight Plan Filed')
- .addFields(
- { name: 'User', value: message.author.tag },
- { name: 'Callsign', value: callsign },
- { name: 'Departure', value: departure },
- { name: 'Arrival', value: arrival },
- { name: 'Aircraft Type', value: aircraftType },
- { name: 'IFR/VFR', value: ifrVfr },
- { name: 'CRZ FL', value: crzFl },
- { name: 'Time', value: new Date().toISOString() }
- );
- await logChannel.send({ embeds: [logEmbed] });
- console.log('Log sent for flight plan command');
- }
- // Update the embed for the departure and arrival airports
- const updateEmbed = async (airport) => {
- const channel = message.guild.channels.cache.get(airportChannels[airport]);
- if (!channel) return;
- const departures = flightPlans[airport].departures.map(plan => `${plan.callsign} | ${plan.destination} | ${plan.squawk || 'No squawk'}`).join('\n') || 'No departures';
- const arrivals = flightPlans[airport].arrivals.map(plan => `${plan.callsign} | ${plan.departedFrom} | ${plan.squawk || 'No squawk'}`).join('\n') || 'No arrivals';
- const embed = new EmbedBuilder()
- .setColor('#88ebff')
- .setTitle(`${airport} | Filed Flight Plans | Departing & Arriving`)
- .addFields(
- { name: '**Departures**', value: departures },
- { name: '**Arrivals**', value: arrivals }
- );
- const row = new ActionRowBuilder()
- .addComponents(
- new ButtonBuilder()
- .setCustomId(`remove_aircraft_${airport.toLowerCase()}`)
- .setLabel('Remove Aircraft')
- .setStyle(ButtonStyle.Danger),
- new ButtonBuilder()
- .setCustomId(`get_details_${airport.toLowerCase()}`)
- .setLabel('Get Details')
- .setStyle(ButtonStyle.Secondary),
- new ButtonBuilder()
- .setCustomId(`assign_squawk_${airport.toLowerCase()}`)
- .setLabel('Assign Squawk')
- .setStyle(ButtonStyle.Primary)
- );
- if (embedMessageIds[airport]) {
- try {
- const embedMessage = await channel.messages.fetch(embedMessageIds[airport]);
- await embedMessage.edit({ embeds: [embed], components: [row] });
- } catch (error) {
- if (error.code === 10008) {
- console.log(`Message for ${airport} in channel ${channel.name} no longer exists.`);
- } else {
- console.error(`Failed to update embed for ${airport} in channel ${channel.name}:`, error);
- }
- }
- }
- };
- await updateEmbed(departure);
- await updateEmbed(arrival);
- } catch (error) {
- console.error('Error in command /fileflightplan:', error);
- await message.reply('There was an error while executing this command!');
- }
- },
- slashExecute: async (interaction) => {
- try {
- console.log('Executing slash command /fileflightplan');
- const callsign = interaction.options.getString('callsign').toUpperCase();
- const departure = interaction.options.getString('departure').toUpperCase();
- const arrival = interaction.options.getString('arrival').toUpperCase();
- const aircraftType = interaction.options.getString('aircrafttype').toUpperCase();
- const ifrVfr = interaction.options.getString('ifrvfr').toUpperCase();
- const crzFl = interaction.options.getString('crzfl').toUpperCase();
- let flightPlans = JSON.parse(fs.readFileSync(flightPlansPath, 'utf-8'));
- embedMessageIds = JSON.parse(fs.readFileSync(embedMessageIdsPath, 'utf-8'));
- if (!flightPlans[departure]) {
- flightPlans[departure] = { departures: [], arrivals: [] };
- }
- if (!flightPlans[arrival]) {
- flightPlans[arrival] = { departures: [], arrivals: [] };
- }
- flightPlans[departure].departures.push({ callsign, destination: arrival, aircraftType, ifrVfr, crzFl });
- flightPlans[arrival].arrivals.push({ callsign, departedFrom: departure, aircraftType, ifrVfr, crzFl });
- fs.writeFileSync(flightPlansPath, JSON.stringify(flightPlans, null, 2));
- await interaction.reply({ content: `Filed flight plan for ${callsign} from ${departure} to ${arrival}.`, ephemeral: true });
- console.log(`Filed flight plan for ${callsign} from ${departure} to ${arrival}`);
- const logChannel = interaction.guild.channels.cache.get(logChannelId);
- if (logChannel) {
- const logEmbed = new EmbedBuilder()
- .setColor('#88ebff')
- .setTitle('Flight Plan Filed')
- .addFields(
- { name: 'User', value: interaction.user.tag },
- { name: 'Callsign', value: callsign },
- { name: 'Departure', value: departure },
- { name: 'Arrival', value: arrival },
- { name: 'Aircraft Type', value: aircraftType },
- { name: 'IFR/VFR', value: ifrVfr },
- { name: 'CRZ FL', value: crzFl },
- { name: 'Time', value: new Date().toISOString() }
- );
- await logChannel.send({ embeds: [logEmbed] });
- console.log('Log sent for flight plan command');
- }
- // Update the embed for the departure and arrival airports
- const updateEmbed = async (airport) => {
- const channel = interaction.guild.channels.cache.get(airportChannels[airport]);
- if (!channel) return;
- const departures = flightPlans[airport].departures.map(plan => `${plan.callsign} | ${plan.destination} | ${plan.squawk || 'No squawk'}`).join('\n') || 'No departures';
- const arrivals = flightPlans[airport].arrivals.map(plan => `${plan.callsign} | ${plan.departedFrom} | ${plan.squawk || 'No squawk'}`).join('\n') || 'No arrivals';
- const embed = new EmbedBuilder()
- .setColor('#88ebff')
- .setTitle(`${airport} | Filed Flight Plans | Departing & Arriving`)
- .addFields(
- { name: '**Departures**', value: departures },
- { name: '**Arrivals**', value: arrivals }
- );
- const row = new ActionRowBuilder()
- .addComponents(
- new ButtonBuilder()
- .setCustomId(`remove_aircraft_${airport.toLowerCase()}`)
- .setLabel('Remove Aircraft')
- .setStyle(ButtonStyle.Danger),
- new ButtonBuilder()
- .setCustomId(`get_details_${airport.toLowerCase()}`)
- .setLabel('Get Details')
- .setStyle(ButtonStyle.Secondary),
- new ButtonBuilder()
- .setCustomId(`assign_squawk_${airport.toLowerCase()}`)
- .setLabel('Assign Squawk')
- .setStyle(ButtonStyle.Primary)
- );
- if (embedMessageIds[airport]) {
- try {
- const embedMessage = await channel.messages.fetch(embedMessageIds[airport]);
- await embedMessage.edit({ embeds: [embed], components: [row] });
- } catch (error) {
- if (error.code === 10008) {
- console.log(`Message for ${airport} in channel ${channel.name} no longer exists.`);
- } else {
- console.error(`Failed to update embed for ${airport} in channel ${channel.name}:`, error);
- }
- }
- }
- };
- await updateEmbed(departure);
- await updateEmbed(arrival);
- } catch (error) {
- if (error.code === 10062) {
- console.log('Interaction no longer valid.');
- } else {
- console.error('Error in slash command /fileflightplan:', error);
- await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
- }
- }
- }
- });
- client.once('ready', async () => {
- console.log('Bot is online!');
- const commands = [
- new SlashCommandBuilder()
- .setName('fileflightplan')
- .setDescription('Files a flight plan')
- .addStringOption(option =>
- option.setName('callsign')
- .setDescription('The callsign of the aircraft')
- .setRequired(true))
- .addStringOption(option =>
- option.setName('departure')
- .setDescription('The departure airport ICAO code')
- .setRequired(true))
- .addStringOption(option =>
- option.setName('arrival')
- .setDescription('The arrival airport ICAO code')
- .setRequired(true))
- .addStringOption(option =>
- option.setName('aircrafttype')
- .setDescription('The aircraft type')
- .setRequired(true))
- .addStringOption(option =>
- option.setName('ifrvfr')
- .setDescription('IFR or VFR')
- .setRequired(true))
- .addStringOption(option =>
- option.setName('crzfl')
- .setDescription('The cruising flight level')
- .setRequired(true))
- ];
- const rest = new REST({ version: '10' }).setToken(token);
- try {
- await rest.put(
- Routes.applicationGuildCommands(clientId, guildId),
- { body: commands }
- );
- console.log('Successfully registered application commands.');
- } catch (error) {
- console.error(error);
- }
- });
- client.on('messageCreate', async message => {
- if (!message.content.startsWith('!') || message.author.bot) return;
- const args = message.content.slice(1).trim().split(/ +/);
- const commandName = args.shift().toLowerCase();
- if (!client.commands.has(commandName)) return;
- const command = client.commands.get(commandName);
- try {
- await command.execute(message, args);
- } catch (error) {
- console.error(error);
- message.reply('There was an error executing that command.');
- }
- });
- client.on('interactionCreate', async interaction => {
- if (interaction.isButton()) {
- const [action, airport] = interaction.customId.split('_').slice(1);
- if (action === 'aircraft') {
- // Handle remove aircraft action
- const flightPlans = JSON.parse(fs.readFileSync(flightPlansPath, 'utf-8'));
- const airportData = flightPlans[airport.toUpperCase()];
- const options = [
- ...airportData.departures.map(plan => ({ label: `${plan.callsign} (Departure)`, value: `departure_${plan.callsign}` })),
- ...airportData.arrivals.map(plan => ({ label: `${plan.callsign} (Arrival)`, value: `arrival_${plan.callsign}` }))
- ];
- if (options.length === 0) {
- return interaction.reply({ content: 'There are no aircraft to remove.', ephemeral: true });
- }
- const row = new ActionRowBuilder()
- .addComponents(
- new StringSelectMenuBuilder()
- .setCustomId(`select_remove_aircraft_${airport.toLowerCase()}`)
- .setPlaceholder('Select an aircraft to remove')
- .addOptions(options)
- );
- await interaction.reply({ content: 'Select an aircraft to remove:', components: [row], ephemeral: true });
- } else if (action === 'details') {
- // Handle get details action
- const flightPlans = JSON.parse(fs.readFileSync(flightPlansPath, 'utf-8'));
- const airportData = flightPlans[airport.toUpperCase()];
- const options = [
- ...airportData.departures.map(plan => ({ label: `${plan.callsign} (Departure)`, value: `departure_${plan.callsign}` })),
- ...airportData.arrivals.map(plan => ({ label: `${plan.callsign} (Arrival)`, value: `arrival_${plan.callsign}` }))
- ];
- if (options.length === 0) {
- return interaction.reply({ content: 'There are no aircraft to get details for.', ephemeral: true });
- }
- const row = new ActionRowBuilder()
- .addComponents(
- new StringSelectMenuBuilder()
- .setCustomId(`select_get_details_${airport.toLowerCase()}`)
- .setPlaceholder('Select an aircraft to get details')
- .addOptions(options)
- );
- await interaction.reply({ content: 'Select an aircraft to get details:', components: [row], ephemeral: true });
- } else if (action === 'squawk') {
- // Handle assign squawk action
- const flightPlans = JSON.parse(fs.readFileSync(flightPlansPath, 'utf-8'));
- const airportData = flightPlans[airport.toUpperCase()];
- const options = [
- ...airportData.departures.map(plan => ({ label: `${plan.callsign} (Departure)`, value: `departure_${plan.callsign}` })),
- ...airportData.arrivals.map(plan => ({ label: `${plan.callsign} (Arrival)`, value: `arrival_${plan.callsign}` }))
- ];
- if (options.length === 0) {
- return interaction.reply({ content: 'There are no aircraft to assign squawk.', ephemeral: true });
- }
- const row = new ActionRowBuilder()
- .addComponents(
- new StringSelectMenuBuilder()
- .setCustomId(`select_assign_squawk_${airport.toLowerCase()}`)
- .setPlaceholder('Select an aircraft to assign squawk')
- .addOptions(options)
- );
- await interaction.reply({ content: 'Select an aircraft to assign squawk:', components: [row], ephemeral: true });
- }
- } else if (interaction.isStringSelectMenu()) {
- const [action, type, callsign] = interaction.values[0].split('_');
- const airport = interaction.customId.split('_')[3].toUpperCase();
- const flightPlans = JSON.parse(fs.readFileSync(flightPlansPath, 'utf-8'));
- if (action === 'remove') {
- if (type === 'departure') {
- flightPlans[airport].departures = flightPlans[airport].departures.filter(plan => plan.callsign !== callsign);
- } else {
- flightPlans[airport].arrivals = flightPlans[airport].arrivals.filter(plan => plan.callsign !== callsign);
- }
- fs.writeFileSync(flightPlansPath, JSON.stringify(flightPlans, null, 2));
- await interaction.update({ content: `Removed ${callsign} from ${type === 'departure' ? 'departures' : 'arrivals'} of ${airport}.`, components: [] });
- // Update the embed for the airport
- const updateEmbed = async (airport) => {
- const channel = interaction.guild.channels.cache.get(airportChannels[airport]);
- if (!channel) return;
- const departures = flightPlans[airport].departures.map(plan => `${plan.callsign} | ${plan.destination} | ${plan.squawk || 'No squawk'}`).join('\n') || 'No departures';
- const arrivals = flightPlans[airport].arrivals.map(plan => `${plan.callsign} | ${plan.departedFrom} | ${plan.squawk || 'No squawk'}`).join('\n') || 'No arrivals';
- const embed = new EmbedBuilder()
- .setColor('#88ebff')
- .setTitle(`${airport} | Filed Flight Plans | Departing & Arriving`)
- .addFields(
- { name: '**Departures**', value: departures },
- { name: '**Arrivals**', value: arrivals }
- );
- const row = new ActionRowBuilder()
- .addComponents(
- new ButtonBuilder()
- .setCustomId(`remove_aircraft_${airport.toLowerCase()}`)
- .setLabel('Remove Aircraft')
- .setStyle(ButtonStyle.Danger),
- new ButtonBuilder()
- .setCustomId(`get_details_${airport.toLowerCase()}`)
- .setLabel('Get Details')
- .setStyle(ButtonStyle.Secondary),
- new ButtonBuilder()
- .setCustomId(`assign_squawk_${airport.toLowerCase()}`)
- .setLabel('Assign Squawk')
- .setStyle(ButtonStyle.Primary)
- );
- if (embedMessageIds[airport]) {
- try {
- const embedMessage = await channel.messages.fetch(embedMessageIds[airport]);
- await embedMessage.edit({ embeds: [embed], components: [row] });
- } catch (error) {
- if (error.code === 10008) {
- console.log(`Message for ${airport} in channel ${channel.name} no longer exists.`);
- } else {
- console.error(`Failed to update embed for ${airport} in channel ${channel.name}:`, error);
- }
- }
- }
- };
- await updateEmbed(airport);
- } else if (action === 'details') {
- const plan = flightPlans[airport][type === 'departure' ? 'departures' : 'arrivals'].find(plan => plan.callsign === callsign);
- if (!plan) {
- return interaction.update({ content: `Details not found for ${callsign}.`, components: [] });
- }
- const detailsEmbed = new EmbedBuilder()
- .setColor('#88ebff')
- .setTitle(`Details for ${callsign}`)
- .addFields(
- { name: 'Callsign', value: plan.callsign },
- { name: 'Departing', value: plan.departedFrom || 'N/A' },
- { name: 'Arriving', value: plan.destination || 'N/A' },
- { name: 'Aircraft Type', value: plan.aircraftType || 'N/A' },
- { name: 'IFR/VFR', value: plan.ifrVfr || 'N/A' },
- { name: 'CRZ FL', value: plan.crzFl || 'N/A' }
- );
- await interaction.update({ embeds: [detailsEmbed], components: [] });
- } else if (action === 'squawk') {
- const modal = new ModalBuilder()
- .setCustomId(`submit_squawk_${type}_${callsign}_${airport}`)
- .setTitle('Assign Squawk Code')
- .addComponents(
- new ActionRowBuilder().addComponents(
- new TextInputBuilder()
- .setCustomId('squawk_code')
- .setLabel('Squawk Code')
- .setStyle(TextInputStyle.Short)
- .setRequired(true)
- )
- );
- await interaction.showModal(modal);
- }
- } else if (interaction.isModalSubmit()) {
- const [action, type, callsign, airport] = interaction.customId.split('_').slice(1);
- const squawkCode = interaction.fields.getTextInputValue('squawk_code');
- const flightPlans = JSON.parse(fs.readFileSync(flightPlansPath, 'utf-8'));
- const plan = flightPlans[airport.toUpperCase()][type === 'departure' ? 'departures' : 'arrivals'].find(plan => plan.callsign === callsign);
- if (!plan) {
- return interaction.reply({ content: `Plan not found for ${callsign}.`, ephemeral: true });
- }
- plan.squawk = squawkCode;
- fs.writeFileSync(flightPlansPath, JSON.stringify(flightPlans, null, 2));
- await interaction.reply({ content: `Assigned squawk code ${squawkCode} to ${callsign}.`, ephemeral: true });
- // Update the embed for the airport
- const updateEmbed = async (airport) => {
- const channel = interaction.guild.channels.cache.get(airportChannels[airport]);
- if (!channel) return;
- const departures = flightPlans[airport].departures.map(plan => `${plan.callsign} | ${plan.destination} | ${plan.squawk || 'No squawk'}`).join('\n') || 'No departures';
- const arrivals = flightPlans[airport].arrivals.map(plan => `${plan.callsign} | ${plan.departedFrom} | ${plan.squawk || 'No squawk'}`).join('\n') || 'No arrivals';
- const embed = new EmbedBuilder()
- .setColor('#88ebff')
- .setTitle(`${airport} | Filed Flight Plans | Departing & Arriving`)
- .addFields(
- { name: '**Departures**', value: departures },
- { name: '**Arrivals**', value: arrivals }
- );
- const row = new ActionRowBuilder()
- .addComponents(
- new ButtonBuilder()
- .setCustomId(`remove_aircraft_${airport.toLowerCase()}`)
- .setLabel('Remove Aircraft')
- .setStyle(ButtonStyle.Danger),
- new ButtonBuilder()
- .setCustomId(`get_details_${airport.toLowerCase()}`)
- .setLabel('Get Details')
- .setStyle(ButtonStyle.Secondary),
- new ButtonBuilder()
- .setCustomId(`assign_squawk_${airport.toLowerCase()}`)
- .setLabel('Assign Squawk')
- .setStyle(ButtonStyle.Primary)
- );
- if (embedMessageIds[airport]) {
- try {
- const embedMessage = await channel.messages.fetch(embedMessageIds[airport]);
- await embedMessage.edit({ embeds: [embed], components: [row] });
- } catch (error) {
- if (error.code === 10008) {
- console.log(`Message for ${airport} in channel ${channel.name} no longer exists.`);
- } else {
- console.error(`Failed to update embed for ${airport} in channel ${channel.name}:`, error);
- }
- }
- }
- };
- await updateEmbed(airport);
- } else if (interaction.isCommand()) {
- const command = client.commands.get(interaction.commandName);
- if (!command) return;
- if (!interaction.member.roles.cache.has(roleID)) {
- return interaction.reply({ content: 'You do not have permission to use this command.', ephemeral: true });
- }
- try {
- console.log(`Executing command /${interaction.commandName}`);
- await command.slashExecute(interaction);
- const logChannel = interaction.guild.channels.cache.get(logChannelId);
- if (logChannel) {
- const logEmbed = new EmbedBuilder()
- .setColor('#88ebff')
- .setTitle('Command Log')
- .addFields(
- { name: 'User', value: interaction.user.tag },
- { name: 'Command', value: interaction.commandName },
- { name: 'Time', value: new Date().toISOString() }
- );
- await logChannel.send({ embeds: [logEmbed] });
- console.log('Log sent for command');
- }
- } catch (error) {
- if (error.code === 10062) {
- console.log('Interaction no longer valid.');
- } else {
- console.error(`Error handling interaction for command ${interaction.commandName}:`, error);
- await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
- }
- }
- }
- });
- client.login(token);
- module.exports = client;
Advertisement
Add Comment
Please, Sign In to add comment