te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - How would I use two different versions of discord.js | Discord.js Bot - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How would I use two different versions of discord.js | Discord.js Bot - Stack Overflow

programmeradmin2浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论