fixed not found message not firing and added some minor changes

This commit is contained in:
mmacierzanka committed 2021-09-07 20:30:51 +02:00
1 parent 3004787cf0
commit 1e2966dfa9
4 files changed
+21 -7

No files matched your search

+2 -2
View File
@@ -3,7 +3,7 @@ import { CommandInteractionData } from "../types/commands.js";
import { MessageCommand } from "../structures/MessageCommand.js";
import { CommandManager } from "./CommandManager.js";
import { CommandNotFound } from "../errors.js";
import { ObjectParameter, Parameter } from "../structures/Parameter.js";
import { Parameter, TargetParameter } from "../structures/Parameter.js";
export class MessageCommandManager extends CommandManager {
protected readonly _list: MessageCommand[] = [];
@@ -31,7 +31,7 @@ export class MessageCommandManager extends CommandManager {
optional: false,
type: "target",
});
const inputParameter = new ObjectParameter(parameter, i.targetId);
const inputParameter = new TargetParameter(parameter, i.targetId);
return {
command: command,
parameters: [inputParameter],
+4 -4
View File
@@ -1,4 +1,4 @@
import { CommandInteraction, Message, MessageEmbed } from "discord.js";
import { Interaction, Message, MessageEmbed } from "discord.js";
import { SystemMessageAppearance, SystemMessageData, MessageType } from "../types/SystemMessage.js";
export class SystemMessageManager {
@@ -78,7 +78,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*
*/
public async send(type: MessageType, data?: SystemMessageData, interaction?: Message | CommandInteraction): Promise<MessageEmbed | Message | void> {
public async send(type: MessageType, data?: SystemMessageData, interaction?: Message | Interaction): Promise<MessageEmbed | Message | void> {
if (this[type]) {
if (this[type].enabled === false) {
return;
@@ -134,7 +134,7 @@ export class SystemMessageManager {
break;
}
}
if (interaction && !(interaction instanceof CommandInteraction)) {
if (interaction && !(interaction instanceof Interaction)) {
const message = await interaction.reply({ embeds: [embed] });
if (message.deletable) {
if (Number.isFinite(this[type].deleteTimeout)) {
@@ -148,7 +148,7 @@ export class SystemMessageManager {
}
}
return message;
} else if (interaction && interaction instanceof CommandInteraction) {
} else if (interaction && interaction instanceof Interaction && (interaction.isCommand() || interaction.isContextMenu())) {
interaction.replied || interaction.deferred ? await interaction.editReply({ embeds: [embed] }) : await interaction.reply({ embeds: [embed] });
if (Number.isFinite(this[type].deleteTimeout)) {
setTimeout(async () => {
+1 -1
View File
@@ -236,7 +236,7 @@ export class Bot extends EventEmitter {
} else if (e instanceof OperationSuccess) {
await this.messages.system.send("SUCCESS", undefined, i as CommandInteraction);
} else if (e instanceof CommandNotFound) {
await this.messages.system.send("NOT_FOUND", { user: i.user, phrase: e.query });
await this.messages.system.send("NOT_FOUND", { user: i.user, phrase: e.query }, i);
} else {
await this.messages.system.send(
"ERROR",
+14
View File
@@ -162,3 +162,17 @@ export class NullParameter extends InputParameter {
super(parameter, null);
}
}
export class TargetParameter extends InputParameter {
constructor(parameter: Parameter, targetId: string) {
super(parameter, targetId);
}
toMessage(c: TextChannel) {
return c.messages.cache.get(this.value?.toString() || "");
}
async toUser(g: Guild) {
return await g.members.fetch({ query: this.value?.toString() });
}
}