Archived
command registering working again
This commit is contained in:
1 parent
149602a382
commit
0f97524474
2 files changed
+40
-3
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import axios from "axios";
|
||||
import { Interaction, Message } from "discord.js";
|
||||
import { TargetID } from "../structures/parameter.js";
|
||||
import { CommandNotFound } from "../errors.js";
|
||||
@@ -7,6 +8,8 @@ import { ChatCommand } from "./ChatCommand.js";
|
||||
import { ContextMenuCommand } from "./ContextMenuCommand.js";
|
||||
import { CommandType } from "./types/commands.js";
|
||||
import { CommandInteractionData } from "./types/commands.js";
|
||||
import { BaseCommandObject } from "../structures/types/api.js";
|
||||
import { Bot } from "../structures/Bot.js";
|
||||
|
||||
export class CommandManager {
|
||||
private readonly _commands: BaseCommand[] = [];
|
||||
@@ -150,4 +153,39 @@ export class CommandManager {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public async register(client: Bot) {
|
||||
const globalCommands = this._commands
|
||||
.filter((c) => {
|
||||
if (!Array.isArray(c.guilds) || c.guilds.length === 0) {
|
||||
if (c.isChatCommand() && !c.slash) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
})
|
||||
.map((c) => c.toObject());
|
||||
const guildCommands: Map<string, BaseCommandObject[]> = new Map();
|
||||
this._commands
|
||||
.filter((c) => Array.isArray(c.guilds) && c.guilds.length > 0)
|
||||
.map((c) => {
|
||||
c.guilds?.map((gId) => {
|
||||
if (!client.client.guilds.cache.get(gId)) {
|
||||
throw new Error(`"${gId}" is not a valid ID for this client.`);
|
||||
}
|
||||
const existingEntry = guildCommands.get(gId);
|
||||
if (!existingEntry) {
|
||||
guildCommands.set(gId, [c.toObject()]);
|
||||
} else {
|
||||
guildCommands.set(gId, [...existingEntry, c.toObject()]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
await axios.put(`https://discord.com/api/v8/applications/${client.applicationId}/commands`, globalCommands, { headers: { Authorization: `Bot ${client.token}` } });
|
||||
await guildCommands.forEach(async (g, k) => {
|
||||
await axios.put(`https://discord.com/api/v8/applications/${client.applicationId}/guilds/${k}/commands`, g, { headers: { Authorization: `Bot ${client.token}` } });
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -151,9 +151,8 @@ export class Bot extends EventEmitter {
|
||||
if (register === undefined || register === true) {
|
||||
console.log("✔");
|
||||
process.stdout.write(`Registering commands... `);
|
||||
//await this.chatCommands.register(this.applicationId, this.token);
|
||||
//console.log("✔");
|
||||
console.log("❌ [Registration module is not functional in this version]");
|
||||
await this.commands.register(this);
|
||||
console.log("✔");
|
||||
} else {
|
||||
console.log("✔\n");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user