#Function returns undefined?

6 messages · Page 1 of 1 (latest)

valid scarab
#

Code:

client.on('interactionCreate', async (interaction) => {
  if (interaction.isCommand()) {
    const { commandName, options } = interaction
    if (commandName === 'istatistik') {
    await interaction.deferReply({ephemeral: true})
    //await interaction.editReply(`Geçiçi olarak devre dışı!`)
    let readyFunction = await isReady(commandName);
    await console.log("Ready function output:") //I know i can merge console.log's to one but if its an array or promise it wont display the input so that's the way for now.
    await console.log(readyFunction)
    }
  }
})

async function isReady(cmdName) {
  let ready = null
  let embed = new Discord.MessageEmbed()
  let returnArray = []
  embed.setColor("RED")
  embed.setTimestamp()
  embed.setFooter({
    text: client.user.username,
iconURL: client.user.avatarURL()
  })
  embed.addField(`:x: Bot hazır değil!`, `Lütfen 10 dakika bekleyip yeniden deneyin!`)
  let sqlSorgusu2 = `SELECT * FROM \`hanibor\`.\`botready\`;`
 await connection.query(sqlSorgusu2, async function (err, results) {
    if (err) throw err.message;
    if(!results[0]){
        console.log(`${cmdName} is being used but bot is not ready.`)
        ready = false
        await returnArray.push(ready, embed)
        await console.log("Return array:")
        await console.log(returnArray)
        return returnArray
    } else if (results[0]) {
      if (results[0].status.toLowerCase()=="ok") {
        ready = true
          await returnArray.push(ready)
          await console.log("Return array:")
          await console.log(returnArray)
          return returnArray
      }
    }
  }); 
}```
Console output:
```Ready function output:
undefined

istatistik is being used but bot is not ready.
Return array:
[
  false,
  MessageEmbed {
    type: 'rich',
    title: null,
    description: null,
    url: null,
    color: 15548997,
    timestamp: 1670611520982,
    fields: [ [Object] ],
    thumbnail: null,
    image: null,
    video: null,
    author: null,
    provider: null,
    footer: {
      text: 'Removed',
      iconURL: 'Removed'
    }
  }
]```
solar panther
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

valid scarab
#

Also tried it with .then results is same.

prime trail
#

You don't return anything in your isReady function.
Not related to discord.js
#useful-servers or #869652447881207858

odd quartz
#

Because you only return from the callback of your db, but not from the outer function🐌