Archived
annotated class methods
This commit is contained in:
1 parent
69b91f82f3
commit
7701e5e4fd
6 files changed
+15
-15
No files matched your search
+2
-2
@@ -116,7 +116,7 @@ export class Bot extends EventEmitter {
|
||||
* @param {boolean} [register=true] - if *true* or *undefined*, the bot will register all slash commands in Discord API
|
||||
* @returns {Promise<boolean>} whether this operation has been completed successfully
|
||||
*/
|
||||
async start(port?: number, register?: boolean): Promise<boolean> {
|
||||
public async start(port?: number, register?: boolean): Promise<boolean> {
|
||||
try {
|
||||
console.log(`\nBot name: ${this.name}`);
|
||||
console.log(`Prefix: ${this.commands.prefix || "/ (only slash commands)"} \n`);
|
||||
@@ -244,7 +244,7 @@ export class Bot extends EventEmitter {
|
||||
* Registers commands from {@link CommandManager} in Discord API
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async register(): Promise<void> {
|
||||
public async register(): Promise<void> {
|
||||
process.stdout.write("Registering commands... ");
|
||||
await axios.put(
|
||||
`https://discord.com/api/v8/applications/${this.applicationId}/commands`,
|
||||
|
||||
+2
-2
@@ -116,7 +116,7 @@ export class Command {
|
||||
* @param {InputParameter[]} [cmdParams] - list of processed parameters passed in a Discord interaction
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
async start(interaction?: Message | CommandInteraction, cmdParams?: InputParameter[]): Promise<void> {
|
||||
public async start(interaction?: Message | CommandInteraction, cmdParams?: InputParameter[]): Promise<void> {
|
||||
const paramFindFn = function (query: string, returnType?: "value" | "object") {
|
||||
return returnType === "object" ? cmdParams?.find((p) => p.name === query) || null : cmdParams?.find((p) => p.name === query)?.value || null;
|
||||
};
|
||||
@@ -173,7 +173,7 @@ export class Command {
|
||||
* Converts {@link Command} instance to object that is recognized by the Discord API
|
||||
* @returns {Object} object
|
||||
*/
|
||||
toCommandObject() {
|
||||
public toCommandObject() {
|
||||
let options: any[] = [];
|
||||
if (this.parameters) {
|
||||
options = this.parameters.map((p) => {
|
||||
|
||||
@@ -40,7 +40,7 @@ export class CommandManager {
|
||||
* @param {string} phrase - command name, alias or keyword
|
||||
* @returns {Command | null} Retrieved {@link Command} object from the manager or *null*
|
||||
*/
|
||||
get(phrase: string): Command | null {
|
||||
public get(phrase: string): Command | null {
|
||||
let command: Command | null = null;
|
||||
this.list.map((c) => {
|
||||
if (c.name == phrase) {
|
||||
@@ -60,7 +60,7 @@ export class CommandManager {
|
||||
* Get list (array) of all {@link Command}s registered in a manager
|
||||
* @returns {Command[]} Array of {@link Command}s registered in a manager
|
||||
*/
|
||||
getList(): Command[] {
|
||||
public getList(): Command[] {
|
||||
const list = [...this.list];
|
||||
return list;
|
||||
}
|
||||
@@ -70,7 +70,7 @@ export class CommandManager {
|
||||
* @param {Command} command - {@link Command} instance object
|
||||
* @returns {boolean} Whether this command has been added successfully
|
||||
*/
|
||||
add(command: Command): boolean {
|
||||
public add(command: Command): boolean {
|
||||
try {
|
||||
if (!(command instanceof Command)) {
|
||||
throw new TypeError("Inavlid argument type");
|
||||
@@ -108,7 +108,7 @@ export class CommandManager {
|
||||
* @param {Message} message - {@link Message} object
|
||||
* @returns {CommandMessagesStructure | null} {@link CommandMessageStructure} or *null*
|
||||
*/
|
||||
fetchFromMessage(message: Message): CommandMessageStructure | null {
|
||||
public fetchFromMessage(message: Message): CommandMessageStructure | null {
|
||||
if (!this.prefix) return null;
|
||||
if (!message.author.bot && message.content.startsWith(this.prefix)) {
|
||||
const content = message.content.replace(this.prefix, "");
|
||||
@@ -167,7 +167,7 @@ export class CommandManager {
|
||||
* @param {CommandInteraction} interaction - {@link CommandInteraction} object
|
||||
* @returns {CommandMessagesStructure | null} {@link CommandMessageStructure} or *null*
|
||||
*/
|
||||
fetchFromInteraction(interaction: CommandInteraction): CommandMessageStructure | null {
|
||||
public fetchFromInteraction(interaction: CommandInteraction): CommandMessageStructure | null {
|
||||
const cmd = this.get(interaction.commandName);
|
||||
if (cmd) {
|
||||
if (interaction.options?.data) {
|
||||
@@ -212,7 +212,7 @@ export class CommandManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
freezeList(): void {
|
||||
public freezeList(): void {
|
||||
if (!Object.isFrozen(this.list)) {
|
||||
Object.freeze(this.list);
|
||||
}
|
||||
|
||||
+1
-1
@@ -152,7 +152,7 @@ export class ObjectID {
|
||||
constructor(id: string) {
|
||||
this.id = id.replace(">", "").replace("<@!", "").replace("<#!", "");
|
||||
}
|
||||
async toObject(
|
||||
public async toObject(
|
||||
guild: Guild,
|
||||
type: "channel" | "user" | "role"
|
||||
): Promise<Role | TextChannel | VoiceChannel | CategoryChannel | GuildMember | NewsChannel | StoreChannel | StageChannel | null> {
|
||||
|
||||
@@ -152,7 +152,7 @@ export class SystemMessageManager {
|
||||
* @param {Message | CommandInteraction} [interaction] - if specified, the generated message will be sent in this channel
|
||||
* @returns {Promise<MessageEmbed | Message | void>} A message that got sent or *void*
|
||||
*/
|
||||
async send(type: MessageType, data?: SystemMessageData, interaction?: Message | CommandInteraction): Promise<MessageEmbed | Message | void> {
|
||||
public async send(type: MessageType, data?: SystemMessageData, interaction?: Message | CommandInteraction): Promise<MessageEmbed | Message | void> {
|
||||
if (this[type]) {
|
||||
if (this[type].enabled === false) {
|
||||
return;
|
||||
|
||||
+3
-3
@@ -16,7 +16,7 @@ export class PermissionsError extends Error {
|
||||
this.command = command;
|
||||
this.user = user || null;
|
||||
}
|
||||
toString() {
|
||||
public toString() {
|
||||
return `User ${this.user?.user.tag} doesn't have enough permissions to run "${this.command.name}" command`;
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ export class ParameterTypeError extends TypeError {
|
||||
this.stringContent = s;
|
||||
this.type = type;
|
||||
}
|
||||
toString() {
|
||||
public toString() {
|
||||
return `Parameter "${this.stringContent}" cannot be converted to ${this.type}`;
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ export class MissingParameterError extends ReferenceError {
|
||||
super();
|
||||
this.argument = a;
|
||||
}
|
||||
toString() {
|
||||
public toString() {
|
||||
return `Your request is missing a "${this.argument.name}" parameter which is not optional`;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user