Getting Bot Variable Into Different Commando Files

蹲街弑〆低调 提交于 2019-12-11 15:14:30

问题


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.

My Bot variable:

const bot = new commando.Client({
    commandPrefix: '!',
    owner: config.ownerID,
    unknownCommandResponse: false
});

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?


回答1:


You could do

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)

All the properties of bot will be accessible as long as you use the above mentioned method.



来源:https://stackoverflow.com/questions/50515465/getting-bot-variable-into-different-commando-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!