Restricted access to CommandManager's list

added getList() method instead of list property, added object freezing when bot is starting up
This commit is contained in:
mmacierzanka committed 2021-08-31 20:23:14 +02:00
1 parent 6bf657c3d2
commit e0c5ea3820
3 files changed
+25 -5

No files matched your search

+7 -3
View File
@@ -132,7 +132,7 @@ export class Bot extends EventEmitter {
const helpMsg: Command = new HelpMessage(this.commands, this.messages.help, this.name);
this.commands.add(helpMsg);
}
Object.freeze(this.commands.list);
this.commands.freezeList();
process.stdout.write("Connecting to Discord... ");
this.client.login(this.token);
this.client.on("ready", async () => {
@@ -248,11 +248,15 @@ export class Bot extends EventEmitter {
process.stdout.write("Registering commands... ");
await axios.put(
`https://discord.com/api/v8/applications/${this.applicationId}/commands`,
this.commands.list.filter((c) => !Array.isArray(c.guilds) && c.slash).map((c) => c.toCommandObject()),
this.commands
.getList()
.filter((c) => !Array.isArray(c.guilds) && c.slash)
.map((c) => c.toCommandObject()),
{ headers: { Authorization: `Bot ${this.token}` } }
);
const guilds: any = {};
await this.commands.list
await this.commands
.getList()
.filter((c) => Array.isArray(c.guilds) && c.guilds.length > 0)
.map((c) => {
c.guilds?.map(async (g) => {