added guild and slash command error + more code safety

This commit is contained in:
mmacierzanka committed 2021-08-26 02:32:47 +02:00
1 parent 113e0f8095
commit a6aa9d2c2b
2 files changed
+10 -1

No files matched your search

+4 -1
View File
@@ -113,9 +113,12 @@ export class Bot extends EventEmitter {
); );
const guilds: any = {}; const guilds: any = {};
this.commands.list this.commands.list
.filter((c) => !!c.guilds) .filter((c) => Array.isArray(c.guilds) && c.guilds.length > 0)
.map((c) => { .map((c) => {
c.guilds?.map(async (g) => { c.guilds?.map(async (g) => {
if (!(await this.client.guilds.fetch(g))) {
throw new Error(`"${g}" for "${c.name}" command is not a valid guild ID`);
}
if (guilds[g]) { if (guilds[g]) {
guilds[g].push(c.toCommandObject()); guilds[g].push(c.toCommandObject());
} else { } else {
+6
View File
@@ -84,6 +84,12 @@ export class Command {
: memberPermissions.any(this.permissions as PermissionResolvable, true) : memberPermissions.any(this.permissions as PermissionResolvable, true)
: false) : false)
) { ) {
if (this.guilds && !this.guilds.find((g) => g == interaction?.guild?.id)) {
throw new Error("This command is not available here");
}
if (!this.slash && interaction instanceof CommandInteraction) {
throw new Error("This command is not available as a slash command");
}
if (interaction instanceof CommandInteraction) { if (interaction instanceof CommandInteraction) {
await interaction.deferReply(); await interaction.deferReply();
} }