简体   繁体   English

有什么办法可以做到这样我就不必重新声明 module.exports 的依赖项了吗?

[英]Is there any way I can make it so I don't have to redeclare dependencies for module.exports?

I am working on a discord bot.我正在开发一个不和谐的机器人。 I'm kinda a new at this, so I followed discordjs.guide for this bot.我对这个有点陌生,所以我关注了这个机器人的 discordjs.guide。 I was wondering if there was a way I could use module.exports, while not having to constantly redeclare dependencies such as const Discord = require('discord.js') or function that I have in app.js.我想知道是否有一种方法可以使用 module.exports,而不必经常重新声明依赖项,例如const Discord = require('discord.js')或 app.js 中的函数。

Repo here: https://github.com/boomermath/grapeoverhaul .此处回购: https : //github.com/boomermath/grapeoverhaul

In your app.js file, whatever parameters you pass into execute() will passover to the command file.在您的app.js文件中,您传递给execute()任何参数都将传递给命令文件。 So just add Discord into the parameters.所以只需将Discord添加到参数中即可。

command.execute(Discord, message, args);

Make sure the order of parameters is the exact same across all files, otherwise this will cause an error确保所有文件的参数顺序完全相同,否则会导致错误

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我无法访问其他脚本中的变量。 (Module.exports 并非在所有地方都有效) - I cannot access the variable in the other script. (Module.exports don't work everywhere) 如何在 node.js 的`module.exports = class` 中创建静态变量 - How can I make static variable in `module.exports = class` in node.js 如何使 typescript 导出与 module.exports 向后兼容 - How can I make typescript export backward compatible with module.exports 我正在尝试使用 module.exports 和 require 将我的逻辑放在一个单独的文件中,但是,我似乎无法弄清楚 - I'm attempting to put my logic in a separate file using module.exports and require, however, I can't seem to figure it out 为什么我不能修改module.exports? 为什么我的浏览器在 `npm run build` 没有问题后会抱怨? - Why can't I modify module.exports? Why does my browser complain after no problems from `npm run build`? 回复:如何将javascript AMD模块导入外部TypeScript模块? (使用module.exports =…时) - Re: How can I import a javascript AMD module into an external TypeScript module? (When using module.exports=…) Discord.js,不能使 discord 嵌入到 module.exports 中 - Discord.js, can't make discord embeds inside module.exports 为什么在玩笑中需要`module.exports`? 我该如何避免呢? - Why do I need `module.exports` in jest? How can I avoid it? 我该如何进行变量设置,以免在以后的功能中重复自己 - How can I make variables so that I don't have to repeat myself in future functions 我可以在Node中以编程方式更改.js文件的module.exports中的JSON对象吗? - Can I change a JSON object that is in module.exports of a .js file programmatically in Node?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM