Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

166
Visualizações
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]})



         




    }
}

So this is my code the temp,lan,lat variables were number but i changed them into string and even checked with the typeof method It gave me a string

But still i'm facing out this error called RangeError [EMBED_FIELD_NAME]: MessageEmbed field names must be non-empty string

Please help me if you know whats the solution

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Try this format:

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

For multiple:

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

Or refer to the other answer.

about 4 years ago · Juan Pablo Isaza Relatório

0

You're trying to add one field using Embed#addFields. Embed#addFields takes in an 25 parameters of EmbedFieldData. The correct syntax using Embed#addFields would be:

foo.addFields(
   { name: 'foo', value: 'bar' }, 
   { name: 'egg', value: 'spam' }
)

You can also use Embed#addField to add one field.

foo.addField('bar', 'baz')
about 4 years ago · Juan Pablo Isaza Relatório

0

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

replace with:

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

        interaction.reply({embeds:[new1]})
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda