将Bot变量放入不同的Commando文件 [英] Getting Bot Variable Into Different Commando Files
本文介绍了将Bot变量放入不同的Commando文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对我的discord.js机器人使用了Commando,它已链接到客户端。我希望能够在其他文件中使用bot变量,主要是为了帮助检查bot是否具有正确的权限。
I use commando for my discord.js bot, and it's linked to the client. I want to be able to use the bot variable in a different file, mainly to help check if the bot has the correct permissions.
我的Bot变量:
const bot = new commando.Client({
commandPrefix: '!',
owner: config.ownerID,
unknownCommandResponse: false
});
这当前在我的index.js文件中,但是我有办法吗
This is currently in my index.js file, but is there a way for me to be able to use it in a different command file?
推荐答案
您可以这样做
index.js
const bot = new commando.Client({
commandPrefix: '!',
owner: config.ownerID,
unknownCommandResponse: false
});
this.bot = bot
然后将在另一个文件中访问像这样:
This would then be accessed in another file like:
this.bot.(property)
bot
的所有属性都可以访问,只要使用上述方法即可。
All the properties of bot
will be accessible as long as you use the above mentioned method.
这篇关于将Bot变量放入不同的Commando文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文