Home > Software design >  Discord.js .cleanContent property lost on Object.keys(), and not loggable
Discord.js .cleanContent property lost on Object.keys(), and not loggable

Time:03-22

I have a Discord.js Message instance, which, as defined in the documentation, should have a .cleanContent property, and it should be a string.

  • console.log(message.cleanContent) works as intended, but
    console.log(message) does not log the cleanContent property.
  • More so, Object.keys(message) does not discover the cleanContent property.
  • However, JSON.parse(JSON.stringify(message)) has a loggable, visible cleanContent in turn.
  • A for(key in message) loop also does not list the .cleanContent.

So, uh.. what is going on here?

The bug is reproducable with this much code:

client.on("messageCreate", (message) => {
  console.log(Object.keys(message))
})

CodePudding user response:

This is due to the fact that it's a getter, as shown here. Getters don't seem to be logged in node.js, unlike in my browser's developer console (Chrome). Getters are different in different environments, so it's difficult to provide a solution.

  • Related