admin管理员组

文章数量:1242804

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 [email protected]
then
npm i [email protected]

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

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 [email protected]
then
npm i [email protected]

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

Share Improve this question asked Nov 28, 2020 at 17:10 user14023978user14023978 2
  • 4 Does this answer your question? how to install multiple versions of package using npm – yi fan song Commented Nov 28, 2020 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 Commented Nov 28, 2020 at 17:13
Add a ment  | 

6 Answers 6

Reset to default 10

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

npm install discord.js11@npm:[email protected]
npm install discord.js12@npm:[email protected]

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

Open your package.json and add:

"dependencies": {
   "DiscordJS11": "npm:[email protected]",
   "DiscordJS12": "npm:[email protected]"
}

Then do:

npm install

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 promise 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

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.

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

npm install discord.js@v12

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.

本文标签: javascriptHow would I use two different versions of discordjsDiscordjs BotStack Overflow