簡體   English   中英

如何在我的 say 命令代碼 discord.js 中修復此錯誤

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

我正在嘗試創建一個自定義嵌入 say 命令,其中機器人將發送一系列問題,然后用戶將回答它(例如問題:“輸入標題”用戶消息:“酷標題”)。 我的代碼和錯誤消息如下。

代碼:


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.

你的第二行說:

var userEmbed = new MessageEmbed()

本來應該是:

var userEmbed = new Discord.MessageEmbed()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM