应用程序没有响应但没有错误 Discord.js

The application did not respond but no error Discord.js

所以我试图制作欢迎系统。 所以基本上我有斜杠命令,我可以在其中设置发送欢迎消息的频道。所以我成功地将我的代码与 mongoDB 连接起来并创建了数据库,但现在的问题是当我调用交互时,我收到了响应消息 应用程序没有响应 但我没有遇到任何令人沮丧的错误。

这是我设置频道的代码:

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)
        }
    }
}

这是我的架构代码:

    const mongoose = require('mongoose')

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

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

您的问题来自 deferReply() 函数。该函数会触发 <application> is thinking... 消息并充当初始响应。但它不包含内容...

那 deferReply() 是干什么用的?

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.

如果您知道这一点...并且出于这个原因想要使用 deferReply()...

这就是您实现它的方式:

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

这就是我建议你做的...

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

像这样实现代码:

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