所以我试着建立一个欢迎系统。因此,基本上,我有斜杠命令,可以在其中设置发送欢迎消息的通道。因此,我成功地将我的代码与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)发布于 2022-05-26 21:24:08
您的问题来自于deferReply()函数。该函数触发<application> is thinking...消息,并充当初始响应。但它不包含内容..。
那么deferReply()是什么?
函数适用于特殊情况,在这种情况下,响应可能需要超过3秒,这是超时前的默认交互应用时间,无论您是试图获取大量数据,还是您的VPS速度慢……它给你大约15分钟的时间来执行这个动作。
如果你知道这个..。为此,您希望使用deferReply() .
这就是您实现它的方法:
await interaction.deferReply() // ephemeral option is valid inside of this function
setTimeout(4000)
await interaction.editReply(/* MESSAGE OPTIONS */),这就是我建议你做的.
我建议您只使用普通的
reply()函数,除非您的用例适合deferReply()。
实现如下代码:
await interaction.reply(/* MESSAGE OPTIONS */)https://stackoverflow.com/questions/72397017
复制相似问题