Home > Net >  The application did not respond but no error Discord.js
The application did not respond but no error Discord.js

Time:05-28

so I was trying to make welcome system. So basicly i have slash command where i can set the channel where welcome messages will be sent. So I succesfully conected my code with mongoDB and created data base, but problem right now is that when i call interaction, i got respond message The application did not respond but i dont get any error which is kinda frustrating.

This is my code for setting channel:

const { SlashCommandBuilder } = require('@discordjs/builders')
const {Permissions, MessageEmbed } = require('discord.js') 
const { Schema } = require('../database-schema/welcome_msg.js')


module.exports = {

    /**
     *  @param {Client} client 
     *  @param {Message} client
     * 
     */

    data: new SlashCommandBuilder()
        .setName('setwelcome')
        .setDescription('set channels for welcome messages')
        .addChannelOption(option =>
                option 
                    .setName('channel')
                    .setDescription('Set the channel where you want bot to send welcome messages')
                    .setRequired(true)
            ),

    async execute(interaction, client, message) {
        try {
            if(interaction.member.permissions.has('ADMINISTRATOR')) return 

            const channel = interaction.options.getChannel('channel')

            Schema.findOne({Guild: interaction.guild.id}, async(err, data) => {
                if(data) {
                    data.Channel = channel.id
                    data.save()
                } else {
                    new  Schema({
                        Guild: interaction.guild.id,
                        Channel: interaction.channel.id
                    }).save()
                }
                interaction.deferReply({content: `${channel} has been set as welcome channel`, ephemeral: true })
                .then(console.log)
                .catch(console.error)
            })


           
        }
        catch(err) {
            console.log(err)
        }
    }
}

and this is my schema code:

    const mongoose = require('mongoose')

const Schema = new mongoose.Schema({
    Guild: String,
    Channel: String,
})

module.exports = mongoose.model('welcome-channel', Schema)

CodePudding user response:

your problem is coming from the deferReply() function. That function triggers the <application> is thinking... message and also acts as an initial response. But it doesn't take in content...

What is deferReply() for then?

The function is for special cases where it may take over 3 seconds to respond which is the default interaction application time before timing out, whether you're trying to fetch large amounts of data or your VPS is slow... It gives you roughly 15 minutes to perform the action.

If you know this... and you'd like to use the deferReply() for this reason...

this is how you'd implement it:

await interaction.deferReply() // ephemeral option is valid inside of this function
setTimeout(4000)
await interaction.editReply(/* MESSAGE OPTIONS */)

This is what I suggest you do...

I suggest you just use the normal reply() function unless your use-case is right for deferReply()

Implement code like this:

await interaction.reply(/* MESSAGE OPTIONS */)
  • Related