簡體   English   中英

由於非空字符串錯誤,Discord.js 未發送嵌入

[英]Discord.js isnt sending the embed due to non-empty string error

const { SlashCommandBuilder } = require('@discordjs/builders')
const discord = require('discord.js')
const open = require('openweather-api-node');
module.exports = {
    data: new SlashCommandBuilder()
        .setName('weather')
        .setDescription('Shows the Weather condition of a place')
        .addStringOption(option =>
            option.setName('city')
                .setDescription('Name of the city')
                .setRequired(true)),

    async execute(Discord, client, interaction) {


        let city = interaction.options.getString('city');

        let weather = new open({
            key: process.env.WEATHER,

            units: 'metric'
        })

        weather.setLanguage('en')
     let info = await   weather.getCurrent({ locationName: city }) 


      if(!info) return interaction.reply({content:"Oops "})
            //location 
            var lon = info.lon.toString()
            var lat = info.lat.toString()
            let Timezone = info.timezone

            //Temperature
            var temp =  info.weather.temp.cur.toString()
            let feel_like = info.weather.feels_like.cur
            let min = info.weather.temp.min
            let max =info.weather.temp.max

            //air condition
            let pressure = info.weather.pressure
            let humidity = info.weather.humidity + '%'
            let wind = info.weather.wind.speed + 'km/h'

            //description

            let sky = info.weather.description
            let status = info.weather.main

        console.log(temp)
        console.log(lon)
        console.log(lat)

            let new1 = new discord.MessageEmbed()
            new1.setTitle(city + `'s Weather`)
            new1.setDescription('bruh pls work')
            new1.setColor('#0099ff')
            new1.addFields('**Location**', `Latitude:`+ lat,true)
            new1.addFields('**Temperature**', `${temp}℃`,true)
            new1.setTimestamp()
            new1.setFooter({ text: 'Information by Open-Weather' })

            interaction.reply({embeds:[new1]})



         




    }
}

您使用 addFields 添加一個字段,也許您應該嘗試 addField

"

試試這種格式:

.addFields( 
{name: 'string', value: 'string', inline: true}
)

您正在嘗試使用Embed#addFields<\/code>添加一個字段。 Embed#addFields<\/a>接受EmbedFieldData<\/a>的 25 個參數。 使用Embed#addFields<\/code>的正確語法是:

foo.addFields(
   { name: 'foo', value: 'bar' }, 
   { name: 'egg', value: 'spam' }
)
        let new1 = new discord.MessageEmbed()
        new1.setTitle(city + `'s Weather`)
        new1.setDescription('bruh pls work')
        new1.setColor('#0099ff')
        new1.addFields('**Location**', `Latitude:`+ lat,true)
        new1.addFields('**Temperature**', `${temp}℃`,true)
        new1.setTimestamp()
        new1.setFooter({ text: 'Information by Open-Weather' })

        interaction.reply({embeds:[new1]})

暫無
暫無

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

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