What’s ExtendedMessage on discord.js



I’m on v12 and after a lot of time I decided to start coding again but I ran into a problem I can’t quite fix. At start I wanted to add a function to the Message class like so

Discord.Message.prototype.no = function(content){
  this.channel.send(`:x: - ${content}`)
};

But after a while I saw that some messages I sent did not have this function and threw me an error msg.no is not a function I used console.log to see what didn’t have the function and it wasn’t a Message, it was a ExtendedMessage class.

My question is, what’s ExtendedMessage ? I found nothing about it on the documentation and when searching for it on google, I only found things related to inline replies etc.. Discord don’t have a class ExtendedMessage

I tried deleting node_modules and reinstalling everything again but it didn’t help.

My dependecies :

  "dependencies": {
    "@blad3mak3r/reddit-memes": "^0.2.5",
    "color": "^4.0.1",
    "discord-buttons": "^4.0.0",
    "discord.bio": "^10.1.2",
    "discord.js": "^12.5.3",
    "easier-pokemon": "^1.0.7",
    "easy-json-database": "^1.5.0",
    "figlet": "^1.5.2",
    "genshin": "^1.2.4",
    "imgur-api.js": "^2.10.6",
    "mal-scraper": "^2.11.3",
    "moment": "^2.29.1",
    "nekos.life": "^2.0.7",
    "node": "^14.17.3",
    "node-osu": "^2.2.1",
    "node-spotify-api": "^1.1.1",
    "node.js": "^0.0.1-security",
    "tiktok-scraper": "^1.4.36",
    "twitch-api-v5": "^2.0.4",
    "user-instagram": "^3.0.0",
    "ytsearcher": "^1.2.4"
  }

Answer

The discord-buttons package uses ExtendedMessage to extend the Message class. You can see here. That’s why in the console it shows up like that. Additionally, arrow functions don’t have their own this. You need to use the function keyword to bind this.

This worked for me

Discord.Message.prototype.no = function(content) {
  this.channel.send(`:x: - ${content}`)
}


Source: stackoverflow