javascript 如果(数据类型!== '字符串')抛出新错误(错误消息);

s4n0splo  于 2023-01-16  发布在  Java
关注(0)|答案(1)|浏览(103)

我需要帮助我的机器人Discord.js,我有

if (typeof data !== 'string') throw new error(errorMessage);
                                        ^
RangeError [EMBED_FIELD_NAME]: MessageEmbed field names must be non-empty strings.
    at Util.verifyString (/node_modules/discord.js/src/util/Util.js:427:41)
    at MessageEmbed.normalizeField (/node_modules/discord.js/src/structures/MessageEmbed.js:554:18)
    at /node_modules/discord.js/src/structures/MessageEmbed.js:576:14
    at Array.map (<anonymous>)
    at MessageEmbed.normalizeFields (/node_modules/discord.js/src/structures/MessageEmbed.js:575:8)
    at MessageEmbed.addFields (/node_modules/discord.js/src/structures/MessageEmbed.js:339:42)
    at Query.<anonymous> (/index-beta.js:3445:8)
    at Query.<anonymous> (/node_modules/mysql/lib/Connection.js:526:10)
    at Query._callback (/node_modules/mysql/lib/Connection.js:488:16)
    at Sequence.end (/node_modules/mysql/lib/protocol/sequences/Sequence.js:83:24) {
  [Symbol(code)]: 'EMBED_FIELD_NAME'
}
Node.js v18.12.1

我的代码:

if (incident(message, messageguild, messagedev) == false) {
                        return
                    }
                    if (maintenance == 1) {
                        message.channel.send(messagemaintenance)
                        .catch(function(err) {
                                
                            discorderror(err,message)
                        })
                        return
                    }
                    fs.stat(botfile, async (error, stats) => { 
                    cpuStats.cpuUsage(async function(percent){
                        var nombreutilisateur = client.users.cache.filter(member => !member.bot).size
                        const patienter = new Discord.MessageEmbed()
                        .setColor("#FF7F00")
                        .setTitle("*Chargement en cours...*")
                        .setDescription("Veuillez patienter...")
                        message.channel.send({ embeds: [patienter]}).catch(async function(err) {    
                            discorderror(err,message)
                        })
                        .then(function(msg) {
                        const infobot = new Discord.MessageEmbed()
                        .setColor('RANDOM')
                        .setTitle("**__Informations du bot__**")
                        .addFields("Propriétaire du bot 👨‍💻 :", "TAG", true)
                        .addFields("Version du bot :", botversion, true)
                        .addFields("Language de Dev du bot :", "Javascript", true)
                        .setFooter({text:"Powered by " + "Me"})
                        var timeout = Date.now()
                        
                        msg.edit({ embeds: [infobot]}).then(function(message) {
                            const patienter = new Discord.MessageEmbed()
                            .setColor("#FF7F00")
                            .setTitle("*Chargement en cours...*")
                            .setDescription("Veuillez patienter...")
                            message.channel.send({ embeds: [patienter]})
                            .then(function(ping) {
                                var symboleping2
                                const structure = new Discord.MessageEmbed()
                                if (`${(ping.createdTimestamp - timeout)}` < 400 ) {
                                    symboleping2 = "🟢"
                                    structure.setColor('#00FF00')
                                } else {
                                    if (`${(ping.createdTimestamp - timeout)}` > 400 & `${(ping.createdTimestamp - timeout)}` < 600 ) {
                                        symboleping2 = "🟡"
                                        structure.setColor('#FFFF00')
                                    } else {
                                        if (`${(ping.createdTimestamp - timeout)}` > 600 & `${(ping.createdTimestamp - timeout)}` < 800 ) {
                                            symboleping2 = "🟠"
                                            structure.setColor('#FF7F00')
                                        } else {
                                            if (`${(ping.createdTimestamp - timeout)}` > 800 ) {
                                                symboleping2 = "🔴"
                                                structure.setColor('#FF0000')
                                            }
                                        }
                                    }
                                }
                                structure.setTitle("**__Information Serveurs__**")
                                .addFields("Ping :","`" + `${(ping.createdTimestamp - timeout)}` + "ms" + "`" + " " + symboleping2)
                                .addFields("Hébergeur :", "[**hebergeur**](link)")
                                .addFields("Type de stockage de données :", "Base de données MySQL")
                                .addFields("Coût :", "30.60€/mois")
                                ping.edit({ embeds: [structure]})
                                .catch(function(err) {
                                    discorderror(err,message)
                                })
                            })
                            .catch(function(err) {
                                discorderror(err,message)
                            })
                        })
                        .catch(function(err) {
                            discorderror(err,message)
                        })
                    })
                    });
                })
                }

我添加了, true,没有工作,我看到:www.example.comstackoverflow.com/questions/72555133/if-typeof-data-string-throw-new-errorerrormessage
没有为我工作,我需要帮助调试或给模板最后一个版本discord.js为服务器验证。
也许我把代码弄错了,所以我才把自己转到你这里来寻求帮助因为我不知道该怎么解决这个问题了.
我的机器人有一个非常长的源代码,我还没有成功地转换成这个最新版本的代码

tjrkku2a

tjrkku2a1#

它不是.addFields("name", "value"),而是:

.addFields(
{name: "name", value: "value"},
{name: "name2", value: "value2"}
)

相关问题