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

222
Visualizações
Discord.js says "message is empty" but console.log shows data

I'm currently working on a project that sends the information of my google-spreadsheets to a discord channel. So, I have some questions:

1) The final data (value), when I try to console.log(value), it worked!

So that means it does get the data from google-spreadsheets and set it to (value).

But when I try to do msg.channel.send(value), it responds to me with a crash and says can't send an empty message which makes me confused, why?

And therefore I can't send this value to my discord channel.


2) My final data (value) as shown at the bottom of my code, is actually an array like this:

{ values: [ [A] , [B] , [C] , [D] , ... ] }

And I don't know how to change them into A,B,C,D form. Does anyone know how to convert them?

const { google } = require('googleapis')
async function google_sheet_get() {
    const auth = new google.auth.GoogleAuth({
        keyFile: "./google_sheets/Google_credentials.json",
        scopes: "https://www.googleapis.com/auth/spreadsheets"
    })
    
    const client = await auth.getClient()
    const googleSheets = google.sheets({version: "v4", auth: client})
    const spreadsheetId = "My Sheet ID"
    const getRows = await googleSheets.spreadsheets.values.get({
        auth,
        spreadsheetId,
        majorDimension: "ROWS",
        range: "'Day1'!B1:F24"
    })
    return getRows.data
}

client.on('messageCreate', msg=> {
    if(msg.content.startsWith(settings.prefix+'ttes')||
    msg.content.startsWith(settings.prefix2+'ttes')) {
        sheet.get().then( value => msg.channel.send(value))
        msg.channel.send("Command ttes success.")
    }
})

Really appreciate the help, thank you.

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

0

I'm guessing that value is not a string, when you look at channel.send(), it accepts either string, "MessagePayload" object or "MessageOptions" object, so if the value is an object it tries to interpret it as either one of those and it fails because the required properties aren't there.

Try converting it to string before sending it, like: msg.channel.send(`${value}`) or msg.channel.send(value.toString().


And as for the second part of the question you might want to take a look at Array.flat() .

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