So, I was wondering if there is any way I can use npm to check the version number for discord.js, like what node has for (process.version), so I can use it in a stats command. It's a small question, but I'm just curious.
So, I was wondering if there is any way I can use npm to check the version number for discord.js, like what node has for (process.version), so I can use it in a stats command. It's a small question, but I'm just curious.
There is no need for npm at all, it would have just read the data from package.json. You can parse the package.json yourself and get discord.js version from there.
const packageJSON = require("./package.json");
client.on("messageCreate", async (message) => {
if (message.author.bot) return;
if (message.content == "!stats") {
const discordJSVersion = packageJSON.dependencies["discord.js"];
const embed = new Discord.MessageEmbed()
.setColor("RANDOM")
.setTitle(`Bot stats - ${client.user.tag}`)
.addField("Discord.js version", discordJSVersion);
message.channel.send({
embeds: [embed]
});
}
});
Written for discord.js ^13.0.1 and CommonJS.
Simple:
// From discord.js code
let embed = new MessageEmbed()
.setTitle(`Discord.js version is ${require("discord.js").version}`);
// From package.json
let embed = new MessageEmbed()
.setTitle(`Discord.js version is ${require("discord.js/package.json").version}`);
message.channel.send({
embeds: [embed]
});