Fixed say crash if the bot don't have permission

This commit is contained in:
2022-06-06 15:13:14 +07:00
parent 915ad3ac46
commit 6d17dc225d
+19
View File
@@ -28,6 +28,13 @@ const EMBEDS = {
user: data instanceof Interaction ? data.user : data.author user: data instanceof Interaction ? data.user : data.author
}); });
}, },
SAY_ERROR: (data: Message | Interaction, error: any) => {
return makeErrorEmbed({
title: `Unable to say`,
description: error.message,
user: data instanceof Interaction ? data.user : data.author
});
},
SUCCESSFULLY_SAID: (data: Message | Interaction) => { SUCCESSFULLY_SAID: (data: Message | Interaction) => {
return makeSuccessEmbed({ return makeSuccessEmbed({
title: 'Successfully said', title: 'Successfully said',
@@ -90,15 +97,27 @@ export default class Say extends DiscordModule {
} }
if (data.isSlashCommand() && data.getChannel()) { if (data.isSlashCommand() && data.getChannel()) {
try {
await data.getChannel()!.send({ content: query }); await data.getChannel()!.send({ content: query });
await data await data
.getMessageComponentInteraction() .getMessageComponentInteraction()
.reply({ ephemeral: true, embeds: [EMBEDS.SUCCESSFULLY_SAID(data.getRaw())] }); .reply({ ephemeral: true, embeds: [EMBEDS.SUCCESSFULLY_SAID(data.getRaw())] });
} catch (err: any) {
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.SAY_ERROR(data.getRaw(), err)]
});
}
} else if (data.isMessage()) { } else if (data.isMessage()) {
const message = data.getMessage(); const message = data.getMessage();
if (message.deletable) await message.delete(); if (message.deletable) await message.delete();
try {
await data.getChannel()!.send({ content: query }); await data.getChannel()!.send({ content: query });
} catch (err: any) {
return await sendHybridInteractionMessageResponse(data, {
embeds: [EMBEDS.SAY_ERROR(data.getRaw(), err)]
});
}
} }
} }
} }