Archived
added guild and slash command error + more code safety
This commit is contained in:
1 parent
113e0f8095
commit
a6aa9d2c2b
2 files changed
+10
-1
No files matched your search
+4
-1
@@ -113,9 +113,12 @@ export class Bot extends EventEmitter {
|
||||
);
|
||||
const guilds: any = {};
|
||||
this.commands.list
|
||||
.filter((c) => !!c.guilds)
|
||||
.filter((c) => Array.isArray(c.guilds) && c.guilds.length > 0)
|
||||
.map((c) => {
|
||||
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]) {
|
||||
guilds[g].push(c.toCommandObject());
|
||||
} else {
|
||||
|
||||
@@ -84,6 +84,12 @@ export class Command {
|
||||
: memberPermissions.any(this.permissions as PermissionResolvable, true)
|
||||
: 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) {
|
||||
await interaction.deferReply();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user