简体   繁体   English

如何在我的 say 命令代码 discord.js 中修复此错误

[英]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").我正在尝试创建一个自定义嵌入 say 命令,其中机器人将发送一系列问题,然后用户将回答它(例如问题:“输入标题”用户消息:“酷标题”)。 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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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