beta1e - improved stability of system messages module

This commit is contained in:
mmacierzanka committed 2021-08-09 14:07:06 +02:00
1 parent 4b37c92781
commit 484be23d15
3 files changed
+10 -8

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "commandbot", "name": "commandbot",
"version": "3.0.0-s-beta1d", "version": "3.0.0-s-beta1e",
"description": "A framework that helps you create your own Discord bot easier.", "description": "A framework that helps you create your own Discord bot easier.",
"main": "dist/cjs/index.js", "main": "dist/cjs/index.js",
"module": "dist/mjs/index.js", "module": "dist/mjs/index.js",
+3 -3
View File
@@ -163,7 +163,7 @@ export class Bot extends EventEmitter {
await this.messages.system.send( await this.messages.system.send(
"NOT_FOUND", "NOT_FOUND",
{ phrase: m.content, user: m.member || undefined }, { phrase: m.content, user: m.member || undefined },
m.channel as TextChannel m
); );
} else { } else {
this.emit("MESSAGE", m); this.emit("MESSAGE", m);
@@ -176,7 +176,7 @@ export class Bot extends EventEmitter {
user: m.member || undefined, user: m.member || undefined,
command: cmdMsg?.command, command: cmdMsg?.command,
}, },
m.channel as TextChannel m
); );
} else { } else {
await this.messages.system.send( await this.messages.system.send(
@@ -186,7 +186,7 @@ export class Bot extends EventEmitter {
user: m.member || undefined, user: m.member || undefined,
error: e, error: e,
}, },
m.channel as TextChannel m
); );
console.error(e); console.error(e);
} }
+6 -4
View File
@@ -65,13 +65,13 @@ export class SystemMessageManager {
* Generates and sends a system message * Generates and sends a system message
* @param {MessageType} type - 'ERROR' | 'PERMISSION' | 'NOT_FOUND' * @param {MessageType} type - 'ERROR' | 'PERMISSION' | 'NOT_FOUND'
* @param {SystemMessageData} [data] - additional data to include in the message * @param {SystemMessageData} [data] - additional data to include in the message
* @param {TextChannel | DMChannel | NewsChannel} [interaction] - if specified, the generated message will be sent in this channel * @param {Message | CommandInteraction} [interaction] - if specified, the generated message will be sent in this channel
* @returns *Promise<MessageEmbed | Message | void>* * @returns *Promise<MessageEmbed | Message | void>*
*/ */
async send( async send(
type: MessageType, type: MessageType,
data?: SystemMessageData, data?: SystemMessageData,
interaction?: TextChannel | DMChannel | NewsChannel | CommandInteraction interaction?: Message | CommandInteraction
): Promise<MessageEmbed | Message | void> { ): Promise<MessageEmbed | Message | void> {
if (this[type]) { if (this[type]) {
if (this[type].enabled === false) { if (this[type].enabled === false) {
@@ -154,7 +154,7 @@ export class SystemMessageManager {
} }
} }
if (interaction && !(interaction instanceof CommandInteraction)) { if (interaction && !(interaction instanceof CommandInteraction)) {
const message = await interaction.send({ embeds: [embed] }); const message = await interaction.reply({ embeds: [embed] });
if (this.deleteTimeout != Infinity && message.deletable) { if (this.deleteTimeout != Infinity && message.deletable) {
setTimeout(async () => { setTimeout(async () => {
await message.delete(); await message.delete();
@@ -165,7 +165,9 @@ export class SystemMessageManager {
interaction && interaction &&
interaction instanceof CommandInteraction interaction instanceof CommandInteraction
) { ) {
interaction.reply({ embeds: [embed] }); interaction.replied || interaction.deferred
? await interaction.editReply({ embeds: [embed] })
: await interaction.reply({ embeds: [embed] });
} else { } else {
return embed; return embed;
} }