将机器人变量放入不同的 Commando 文件中

Getting Bot Variable Into Different Commando Files

我为我的 discord.js 机器人使用 commando,它已链接到客户端。我希望能够在不同的文件中使用 bot 变量,主要是为了帮助检查 bot 是否具有正确的权限。

我的机器人变量:

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

这目前在我的 index.js 文件中,但有没有办法让我能够在不同的命令文件中使用它?

你可以

index.js

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

this.bot = bot

这将在另一个文件中访问,例如:

this.bot.(property)

只要使用上述方法,bot的所有属性都可以访问