简体   繁体   中英

How can I fix this error in my say command code discord.js

I'm trying to create a custom embed say command where the bot would send a series of questions and then the user would answer it (eg Question: "Enter the title" User message: "Cool title"). My code and error message is below.

Code:


var embed = new Discord.MessageEmbed()
.setColor('#7289da')

var userEmbed = new MessageEmbed()

module.exports = {
    name: 'sayc',
    description: "Custom embed say command",
    execute(message, args){
        embed.setTitle("Construct your custom embed message by answering the questions below");
        embed.setFooter("Enter 'skip' for any question if you would like to leave that element out")
        embed.setDescription("1. Enter the channel you would like the bot to send this message in");
        message.channel.send(embed);
        const channel = message.guild.channels.cache.get(args.slice(0).join(""));
        
        embed.setDescription("2. Enter the title of your embedded message");
        message.channel.send(embed);
        const title = args.slice(0).join("");
        if (title != "skip"){
            userEmbed.setTitle(title);
        }

        embed.setDescription("3. Enter the URL of your title");
        message.channel.send(embed);
        const url = args.slice(0).join("");
        if (url != "skip"){
            userEmbed.setURL(url);
        }

        embed.setDescription("4. Enter the author");
        message.channel.send(embed);
        const author = args.slice(0).join("");
        if (author != "kip"){
            userEmbed.setAuthor(author);
        }

        embed.setDescription("5. Enter the description");
        message.channel.send(embed);
        const description = args.slice(0).join("");
        if (description != "skip"){
            userEmbed.setDescription(description);
        }

        embed.setDescription("5. Enter the thumbnail (link)");
        message.channel.send(embed);
        const thumbnail = args.slice(0).join("");
        if (thumbnail != "skip"){
            userEmbed.setThumbnail(thumbnail);
        }

        embed.setDescription("6. Enter how many fields you would like");
        message.channel.send(embed);
        const fieldsn = args.join();
        if (fieldsn != "skip" || fieldsn != "0" ){
            for (var i = 0; i <= fieldsn; i++){
                embed.setDescription("6. Enter the name of this field");
                message.channel.send(embed);
                var fieldname = args.slice(0).join("");
                embed.setDescription("6. Enter the value of this field");
                message.channel.send(embed);
                var fieldvalue = args.slice(0).join("");
                userEmbed.addField(fieldname, fieldvalue, true)
            }
        }

        embed.setDescription("7. Enter the image you would like attached");
        message.channel.send(embed);
        const image = args.slice(0).join("");
        if (image != "skip" ){
            userEmbed.setImage(image);
        }

        embed.setDescription("8. Enter the timestamp");
        message.channel.send(embed);  
        const timestamp = args.slice(0).join("");
        if (timestamp != "skip"){
            userEmbed.setTimestamp(timestamp);
        }

        embed.setDescription("9. Enter the footer");
        message.channel.send(embed);
        const footer = args.slice(0).join("");
        if (footer != "skip"){
            userEmbed.setFooter(footer);
        }

        channel.send(userEmbed);
    }
}

Error:

if (!name) throw new RangeError('EMBED_FIELD_NAME');
               ^

RangeError [EMBED_FIELD_NAME]: MessageEmbed field names may not be empty.

Your second line says:

var userEmbed = new MessageEmbed()

It should've been:

var userEmbed = new Discord.MessageEmbed()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM