forked from PluralFlux/PluralFlux
desperately trying to make error handling work
This commit is contained in:
5
bot.js
5
bot.js
@@ -36,12 +36,11 @@ client.on(Events.MessageCreate, async (message) => {
|
|||||||
|
|
||||||
const command = commands.get(commandName);
|
const command = commands.get(commandName);
|
||||||
if (command) {
|
if (command) {
|
||||||
await command.execute(message, client, args).catch(async (e) => {
|
await command.execute(message, client, args);
|
||||||
throw new Error(`Error executing ${commandName}: ${e.message}`);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(error) {
|
catch(error) {
|
||||||
|
console.error(error);
|
||||||
return await message.reply(error.message);
|
return await message.reply(error.message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ const cmds = new Map();
|
|||||||
cmds.set('member', {
|
cmds.set('member', {
|
||||||
description: enums.help.SHORT_DESC_MEMBER,
|
description: enums.help.SHORT_DESC_MEMBER,
|
||||||
async execute(message, client, args) {
|
async execute(message, client, args) {
|
||||||
const reply = await memberHelper.parseMemberCommand(message.author, args, message.attachments[0] = null);
|
const reply = await memberHelper.parseMemberCommand(message.author, args, message.attachments[0] = null).catch(e => message.reply(e));
|
||||||
if (typeof reply === 'string') {
|
if (typeof reply === 'string') {
|
||||||
await message.reply(reply);
|
await message.reply(reply);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ const commandList = ['--help', 'add', 'remove', 'name', 'listall', 'displayName'
|
|||||||
*
|
*
|
||||||
* @param {User} author - The id of the message author
|
* @param {User} author - The id of the message author
|
||||||
* @param {string[]} args - The message arguments
|
* @param {string[]} args - The message arguments
|
||||||
* @param {string | null} attachmentUrl - The message attachments
|
* @param {string | null} attachmentUrl - The message attachment url.
|
||||||
* @returns {Promise<string> | Promise <EmbedBuilder>} A message, or an information embed.
|
* @returns {Promise<string> | Promise <EmbedBuilder>} A message, or an informational embed.
|
||||||
*/
|
*/
|
||||||
mh.parseMemberCommand = async function(author, args, attachmentUrl){
|
mh.parseMemberCommand = async function(author, args, attachmentUrl){
|
||||||
const authorId = author.id;
|
const authorId = author.id;
|
||||||
|
|||||||
@@ -42,10 +42,10 @@ msgh.parseProxyTags = async function (authorId, attachment, content){
|
|||||||
const members = await memberHelper.getMembersByAuthor(authorId);
|
const members = await memberHelper.getMembersByAuthor(authorId);
|
||||||
|
|
||||||
const proxyMessage = {}
|
const proxyMessage = {}
|
||||||
members.forEach(member => {
|
members.filter(member => member.proxy).forEach(member => {
|
||||||
if (content.length <= member.proxy.length && !attachment) throw new Error(enums.err.NO_MESSAGE_SENT_WITH_PROXY);
|
|
||||||
const splitProxy = member.proxy.split("text");
|
const splitProxy = member.proxy.split("text");
|
||||||
if(content.startsWith(splitProxy[0]) && content.endsWith(splitProxy[1])) {
|
if(content.startsWith(splitProxy[0]) && content.endsWith(splitProxy[1])) {
|
||||||
|
if (content.length <= member.proxy.length && !attachment) throw new Error(enums.err.NO_MESSAGE_SENT_WITH_PROXY);
|
||||||
proxyMessage.proxy = member.proxy;
|
proxyMessage.proxy = member.proxy;
|
||||||
proxyMessage.message = content.slice(member.proxy.length).trim();
|
proxyMessage.message = content.slice(member.proxy.length).trim();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user