我在我的 discord bot v14 中收到此错误“已发送或推迟对此交互的回复。”"/>
我在我的 discord bot v14 中收到此错误“已发送或推迟对此交互的回复。”
我正在尝试使用机器人创建一个补丁说明命令,我很难创建模态并使其正常运行,但是在填写和提交模态时它不会自动关闭,我该如何解决?
const { SlashCommandBuilder, EmbedBuilder, PermissionsBitField, ActionRowBuilder, ModalBuilder, TextInputBuilder, TextInputStyle } = require('discord.js');
module.exports = {
data: new SlashCommandBuilder()
.setName('anuncio')
.setDescription('Postar um novo anúncio')
.addChannelOption(canal =>
canal.setName('canal')
.setDescription('Canal para postar o patch notes')),
async execute(interaction) {
if (!interaction.member.permissions.has(PermissionsBitField.Flags.Administrator)) {
return interaction.reply({ content: 'Você não tem permissão para usar este comando.', ephemeral: true });
}
let canal = interaction.options.getChannel('canal');
const modal = new ModalBuilder() // inicio modal
.setCustomId('Anuncio')
.setTitle('Novo Anuncio');
const tituloInput = new TextInputBuilder()
.setCustomId('tituloInput')
.setMaxLength(255)
.setLabel("Qual o título do Anuncio ?")
.setPlaceholder('Digite o título do anuncio')
.setStyle(TextInputStyle.Short);
const infoInput = new TextInputBuilder()
.setCustomId('infoInput')
.setLabel("Qual o corpo do anuncio ?")
.setMaxLength(2048)
.setPlaceholder('Digite as informações do anuncio')
.setStyle(TextInputStyle.Paragraph);
const firstActionRow = new ActionRowBuilder().addComponents(tituloInput);
const secondActionRow = new ActionRowBuilder().addComponents(infoInput);
modal.addComponents(firstActionRow, secondActionRow);
await interaction.showModal(modal);
const submitted = await interaction.awaitModalSubmit({
// Timeout after a minute of not receiving any valid Modals
time: 60000,
}).catch(error => {
// Catch any Errors that are thrown (e.g. if the awaitModalSubmit times out after 60000 ms)
console.error(error)
})
if (submitted) {
const titulo = submitted.fields.getTextInputValue('tituloInput');
const msg = submitted.fields.getTextInputValue('infoInput');
const Embed = new EmbedBuilder()
.setColor("Random")
.setAuthor({ name: 'Anúncio!
更多推荐
我在我的 discord bot v14 中收到此错误“已发送或推迟对此交互的回复。”
发布评论