Home > database >  How can i get my discord.js v14 bot to stop saying "The application did not respond" if th
How can i get my discord.js v14 bot to stop saying "The application did not respond" if th

Time:01-08

i have multiple commands that work perfectly fine but i always get this message in return.

enter image description here

here is the code for that command. it works perfectly fine i guess it just doesn't respond to the interaction even though i feel like it should be?

how can i get it to ignore this message or reply properly?

const Discord = require('discord.js');
const { EmbedBuilder, SlashCommandBuilder } = require('discord.js');

module.exports = {
  data: new SlashCommandBuilder()
    // command name
    .setName('totalfrozencheckouts')
    // command description
    .setDescription('Add up every message in the frozen checkouts channel after a specific message ID')
    .addStringOption(option =>
      option.setName('messageid')
        .setDescription('The message ID')
        .setRequired(true)),
    async execute(interaction) {
        const channel = '<#'   process.env.FROZENCHECKOUTS   '>';
        const messageId = interaction.options.getString("messageid");
        
        // Check if the channel mention is valid
        if (!channel.startsWith('<#') || !channel.endsWith('>')) {
            return interaction.channel.send(`Invalid channel mention. Please use the format: ${this.usage}`);
        }
        
        // Extract the channel ID from the channel mention
        const channelId = channel.slice(2, -1);
        
        // Try to fetch the messages from the requested channel and message ID
        interaction.guild.channels.cache.get(channelId).messages.fetch({ after: messageId })
            .then(messages => {
            // Create an array of the message contents that are numbers
            const numbers = messages.map(message => message.content).filter(content => !isNaN(content));
        
            // Check if there are any messages
            if (numbers.length === 0) {
                return interaction.channel.send(`No messages were found in ${channel} after message ID https://discord.com/channels/1059607354678726666/1060019655663689770/${messageId}`);
            }
        
            // Adds up the messages
            const sum = numbers.reduce((accumulator) => accumulator   1, 1);

            // Create an embed object
            const embed = new EmbedBuilder()
            .setColor(0x4bd8c1)
            .setTitle(`Total Checkouts in #frozen-checkouts for today is:`)
            .addFields(
                {name: 'Total Checkouts', value: sum.toString() , inline: true},
            )
            .setThumbnail('https://i.imgur.com/7cmn8uY.png')
            .setTimestamp()
            .setFooter({ text: 'Frozen ACO', iconURL: 'https://i.imgur.com/7cmn8uY.png' });


            // Send the embed object
            interaction.channel.send({embeds: [embed]});
            })

            .catch(error => {
            console.error(error);
            interaction.channel.send('An error occurred while trying to fetch the messages. Please try again later.');
            });
        }
    }

I don't really know what to try because it literally works I just don't know how to get it to either ignore that message or respond with nothing. It doesn't break the bot its just annoying to look at.

CodePudding user response:

Use interaction.reply instead of interaction.channel.send to reply.

  • Related