4

I want to use the following versions of discord.js for my discord bot:

discord.js v11.6.4 discord.js v12.4.1

I've tried installing each of them one after the other but to no avail.

first
npm i discord.js@11.6.4
then
npm i discord.js@12.4.1

Is there a way to distinct discordv11 from v12 in the package.json and use both modules in one bot?

  • 4
    Does this answer your question? [how to install multiple versions of package using npm](https://stackoverflow.com/questions/26414587/how-to-install-multiple-versions-of-package-using-npm) – yi fan song Nov 28 '20 at 17:12
  • 1
    Yes, but there should be a good reason to use both, if something from v11 has been removed in v12 then perhaps there's another to achieve the same thing. – yi fan song Nov 28 '20 at 17:13

6 Answers6

10

You need to use npm's aliases feature (note that its only available from npm v6.9.0)

npm install discord.js11@npm:discord.js@11.6.4
npm install discord.js12@npm:discord.js@12.4.1

then you can access it as

const discord11 = require('discord.js11')
const discord12 = require('discord.js12')

Also I don't know why your using discord.js v11, v12 should have full coverage and more, your probably better off using just djs v12

Jytesh
  • 815
  • 4
  • 15
1

Open your package.json and add:

"dependencies": {
   "DiscordJS11": "npm:discord.js@11.6.4",
   "DiscordJS12": "npm:discord.js@12.4.1"
}

Then do:

npm install
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Farrel Athaillah
  • 107
  • 1
  • 10
0

This seems to be a bad practice. Imagine there are breaking changes in DiscordJs 11 to 12 with DiscordAPI. I guess you want to work with new features from v12, maybe it's better to compromise with existing stuff or rewrite v11 code to v12. I hope there aren't much of any breaking changes in v11 to v12, v13 had a lot of breaking changes though

Prithvi Reddy
  • 11
  • 1
  • 5
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Nov 09 '21 at 14:57
0

You can install discord.js-v11 and discord.js-v12 packages in npm.

In terminal/cmd:

npm install discord.js-v11

In the code:

const { Client, Intents } = require('discord.js-v11');
// code...

It also works with V12. Just write v12 instead of v11.

andrasxa
  • 43
  • 1
  • 4
0

Hmm You Can Use Verison 12 this verison available Features Verison 11

npm install discord.js@v12
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 11 '22 at 15:45
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/32660133) – blurfus Sep 12 '22 at 22:05
0

When you install a module in NPM you will not be able to have the same module in 2 different versions. What you can do is have 2 different modules but with the same function.

You will do this:

npm i discord.js@11

Then, you will rename the folder created in node_modules. The folder is called discord.js, you will rename it to discord.js_v11

Now, you will install v12 with

npm i discord.js@12

And now, you will do the same with the other, but instead of putting discord.js_v11 you will change it to discord.js_v12

Now, in the main file of your bot you will do this:

const DiscordV11 = require("discord.js_v11")
const DiscordV12 = require("discord.js_v12")

Node will understand that they are 2 different modules, then it will accept it for you. I hope to be helpful.

1ly4s0
  • 54
  • 2