所以我試圖制作歡迎系統。所以基本上我有斜杠命令,我可以設定發送歡迎訊息的通道。所以我成功地將我的代碼與 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)
uj5u.com熱心網友回復:
您的問題來自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://www.uj5u.com/net/482019.html
下一篇:MongoDB欄位必須是陣列
