Uncaught ReferenceError ReferenceError: channel is not defined

问题描述 投票:0回答:0

我正在编写一个创建票证的不和谐机器人

我想知道如何在我刚刚创建的频道上发送消息

所以我尝试了 .then,但它不起作用,所以我不明白为什么:/

我尝试了很多方法,只是访问网络或在 YouTube 上观看视频,但没有一个有效

这是我的代码:

client.on("interactionCreate", async interaction =>  {
    if(interaction.isCommand()){
        if(interaction.commandName == "ticket"){

            const Embed = new EmbedBuilder()
                .setColor(0x0099FF)
                .setTitle('Do you need help ?')
                .setDescription('By clicking on the button,\nModerators will answer your questions/reports!')
                .setFooter({ text: 'Created by Skorflex#9141', iconURL: 'https://cdn.discordapp.com/attachments/1082613588507766784/1082613661140537404/logo-transparent.png' });
            
            const row = new ActionRowBuilder()
                .addComponents(
                    new ButtonBuilder()
                        .setCustomId('button')
                        .setLabel('Open a ticket')
                        .setStyle(ButtonStyle.Primary),
                );

            await interaction.reply({ embeds: [Embed], components: [row] });

        }
    }
    if(interaction.isButton()){
        if(interaction.customId === "button"){

            const server = client.guilds.cache.get(guildId);

            

            server.channels.create({name:`ticket-${interaction.user.username}`})
            .then(channel => {
                let category = client.channels.cache.get(ticket_category);

                if (!category) throw new Error("Category channel does not exist");
                    channel.setParent(category.id);
                }).catch(console.error);

                interaction.reply({content: "Your ticket is available !", ephemeral: true})

                const Embed = new EmbedBuilder()
                .setColor(0x0099FF)
                .setTitle('Thank you for contacting support')
                .setDescription('Describe your problem')

                const row = new ActionRowBuilder()
                .addComponents(
                    new ButtonBuilder()
                        .setCustomId('closebutton')
                        .setLabel('Close the ticket')
                        .setStyle(ButtonStyle.Primary),
                );
                
                channel.send({embeds:[Embed], row:[row]})
        }
    }
})
javascript node.js discord bots channel
© www.soinside.com 2019 - 2024. All rights reserved.