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

时间:2020-09-03 20:55:01

标签: javascript discord discord.js

我正在尝试创建一个自定义的嵌入say命令,该bot会发送一系列问题,然后用户会回答该问题(例如问题:“输入标题”,用户消息:“酷标题”)。我的代码和错误消息如下。

代码:


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);
    }
}

错误:

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

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

1 个答案:

答案 0 :(得分:0)

您的第二行说:

 window.addEventListener('beforeunload', (event) => {
  // Cancel the event as stated by the standard.
  event.preventDefault();
  // Chrome requires returnValue to be set.
  event.returnValue = '';
});

应该是:

var userEmbed = new MessageEmbed()