我在我的 discord bot v14 中收到此错误“已发送或推迟对此交互的回复。”

编程入门 行业动态 更新时间:2024-10-05 05:19:11

<a href=https://www.elefans.com/category/jswz/34/1771440.html style=我在我的 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 中收到此错误“已发送或推迟对此交互的回复。”

本文发布于:2024-05-30 17:57:34,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:我在   对此   错误   bot   discord

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!