Archived
slash register test
This commit is contained in:
1 parent
861faec976
commit
ceaa0dd803
5 files changed
+28
-3
No files matched your search
+8
-1
@@ -11,6 +11,7 @@ import { HelpMessage } from "./Help.js";
|
||||
import * as http from "http";
|
||||
import { SystemMessageManager } from "./SystemMessage.js";
|
||||
import { EventEmitter } from "events";
|
||||
import axios from "axios";
|
||||
|
||||
export declare interface Bot {
|
||||
on(event: "READY", listener: Function): this;
|
||||
@@ -103,7 +104,13 @@ export class Bot extends EventEmitter {
|
||||
this.client.on("ready", async () => {
|
||||
console.log("✔");
|
||||
process.stdout.write("Registering commands... ");
|
||||
|
||||
this.commands.list.map(async (c) => {
|
||||
await axios.post(
|
||||
`https://discord.com/api/v8/applications/${this.applicationId}/commands`,
|
||||
c.toCommandObject(),
|
||||
{ headers: { Authorization: `Bot ${this.token}` } }
|
||||
);
|
||||
});
|
||||
console.log("✔\n");
|
||||
this.emit("READY");
|
||||
});
|
||||
|
||||
@@ -54,6 +54,9 @@ export class Command {
|
||||
this.guilds = options.guilds || [];
|
||||
this.visible = options.visible != undefined ? options.visible : true;
|
||||
this.function = options.function;
|
||||
/*if (!new RegExp("^[w-]{1,32}$").test(this.name)) {
|
||||
throw new Error(`Incorrect command name: ${this.name}`);
|
||||
}*/
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,6 +97,14 @@ export class Command {
|
||||
}
|
||||
}
|
||||
|
||||
toCommandObject() {
|
||||
return {
|
||||
name: this.name,
|
||||
description: this.description,
|
||||
options: [],
|
||||
};
|
||||
}
|
||||
|
||||
private static processPhrase(phrase?: string | string[]): string[] {
|
||||
if (Array.isArray(phrase)) {
|
||||
const buff = phrase.map((p) => {
|
||||
|
||||
@@ -17,6 +17,8 @@ export class HelpMessage extends Command {
|
||||
parameters: [
|
||||
{
|
||||
name: "Command name",
|
||||
description:
|
||||
"Name of the command that you want to get details about",
|
||||
optional: true,
|
||||
type: "string",
|
||||
},
|
||||
|
||||
+3
-2
@@ -1,9 +1,10 @@
|
||||
import { ParameterTypeError } from "./errors.js";
|
||||
import { ParameterType, ParameterResolvable } from "./types.js";
|
||||
import { ParameterType, ParameterResolvable, Choice } from "./types.js";
|
||||
export interface Parameter {
|
||||
name: string;
|
||||
description?: string;
|
||||
optional: boolean;
|
||||
type: ParameterType;
|
||||
choices?: Choice[];
|
||||
}
|
||||
export const ProcessArgument = (
|
||||
a: string,
|
||||
|
||||
@@ -71,3 +71,7 @@ export type ParameterResolvable =
|
||||
| TextChannel
|
||||
| VoiceChannel
|
||||
| NewsChannel;
|
||||
export interface Choice {
|
||||
name: string;
|
||||
value: string;
|
||||
}
|
||||
Reference in new issue
Block a user