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 * as http from "http";
|
||||||
import { SystemMessageManager } from "./SystemMessage.js";
|
import { SystemMessageManager } from "./SystemMessage.js";
|
||||||
import { EventEmitter } from "events";
|
import { EventEmitter } from "events";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
export declare interface Bot {
|
export declare interface Bot {
|
||||||
on(event: "READY", listener: Function): this;
|
on(event: "READY", listener: Function): this;
|
||||||
@@ -103,7 +104,13 @@ export class Bot extends EventEmitter {
|
|||||||
this.client.on("ready", async () => {
|
this.client.on("ready", async () => {
|
||||||
console.log("✔");
|
console.log("✔");
|
||||||
process.stdout.write("Registering commands... ");
|
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");
|
console.log("✔\n");
|
||||||
this.emit("READY");
|
this.emit("READY");
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ export class Command {
|
|||||||
this.guilds = options.guilds || [];
|
this.guilds = options.guilds || [];
|
||||||
this.visible = options.visible != undefined ? options.visible : true;
|
this.visible = options.visible != undefined ? options.visible : true;
|
||||||
this.function = options.function;
|
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[] {
|
private static processPhrase(phrase?: string | string[]): string[] {
|
||||||
if (Array.isArray(phrase)) {
|
if (Array.isArray(phrase)) {
|
||||||
const buff = phrase.map((p) => {
|
const buff = phrase.map((p) => {
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ export class HelpMessage extends Command {
|
|||||||
parameters: [
|
parameters: [
|
||||||
{
|
{
|
||||||
name: "Command name",
|
name: "Command name",
|
||||||
|
description:
|
||||||
|
"Name of the command that you want to get details about",
|
||||||
optional: true,
|
optional: true,
|
||||||
type: "string",
|
type: "string",
|
||||||
},
|
},
|
||||||
|
|||||||
+3
-2
@@ -1,9 +1,10 @@
|
|||||||
import { ParameterTypeError } from "./errors.js";
|
import { ParameterType, ParameterResolvable, Choice } from "./types.js";
|
||||||
import { ParameterType, ParameterResolvable } from "./types.js";
|
|
||||||
export interface Parameter {
|
export interface Parameter {
|
||||||
name: string;
|
name: string;
|
||||||
|
description?: string;
|
||||||
optional: boolean;
|
optional: boolean;
|
||||||
type: ParameterType;
|
type: ParameterType;
|
||||||
|
choices?: Choice[];
|
||||||
}
|
}
|
||||||
export const ProcessArgument = (
|
export const ProcessArgument = (
|
||||||
a: string,
|
a: string,
|
||||||
|
|||||||
@@ -71,3 +71,7 @@ export type ParameterResolvable =
|
|||||||
| TextChannel
|
| TextChannel
|
||||||
| VoiceChannel
|
| VoiceChannel
|
||||||
| NewsChannel;
|
| NewsChannel;
|
||||||
|
export interface Choice {
|
||||||
|
name: string;
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user