mirror of
https://github.com/ahmadk953/poixpixel-discord-bot.git
synced 2025-05-11 19:23:06 +00:00
Added Basic Leveling System and QoL Updates
This commit is contained in:
parent
7af6d5914d
commit
b5ce514397
15 changed files with 970 additions and 39 deletions
|
@ -20,20 +20,40 @@ export default {
|
|||
|
||||
try {
|
||||
await command.execute(interaction);
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
console.error(`Error executing ${interaction.commandName}`);
|
||||
console.error(error);
|
||||
|
||||
if (interaction.replied || interaction.deferred) {
|
||||
await interaction.followUp({
|
||||
content: 'There was an error while executing this command!',
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
const isUnknownInteractionError =
|
||||
error.code === 10062 ||
|
||||
(error.message && error.message.includes('Unknown interaction'));
|
||||
|
||||
if (!isUnknownInteractionError) {
|
||||
try {
|
||||
if (interaction.replied || interaction.deferred) {
|
||||
await interaction
|
||||
.followUp({
|
||||
content: 'There was an error while executing this command!',
|
||||
flags: ['Ephemeral'],
|
||||
})
|
||||
.catch((e) =>
|
||||
console.error('Failed to send error followup:', e),
|
||||
);
|
||||
} else {
|
||||
await interaction
|
||||
.reply({
|
||||
content: 'There was an error while executing this command!',
|
||||
flags: ['Ephemeral'],
|
||||
})
|
||||
.catch((e) => console.error('Failed to send error reply:', e));
|
||||
}
|
||||
} catch (replyError) {
|
||||
console.error('Failed to respond with error message:', replyError);
|
||||
}
|
||||
} else {
|
||||
await interaction.reply({
|
||||
content: 'There was an error while executing this command!',
|
||||
flags: ['Ephemeral'],
|
||||
});
|
||||
console.warn(
|
||||
'Interaction expired before response could be sent (code 10062)',
|
||||
);
|
||||
}
|
||||
}
|
||||
} else if (interaction.isButton()) {
|
||||
|
@ -73,7 +93,7 @@ export default {
|
|||
});
|
||||
}
|
||||
} else {
|
||||
console.log('Unhandled interaction type:', interaction);
|
||||
console.warn('Unhandled interaction type:', interaction);
|
||||
return;
|
||||
}
|
||||
},
|
||||
|
|
|
@ -8,6 +8,10 @@ import {
|
|||
resetCounting,
|
||||
} from '../util/countingManager.js';
|
||||
import logAction from '../util/logging/logAction.js';
|
||||
import {
|
||||
checkAndAssignLevelRoles,
|
||||
processMessage,
|
||||
} from '../util/levelingSystem.js';
|
||||
|
||||
export const messageDelete: Event<typeof Events.MessageDelete> = {
|
||||
name: Events.MessageDelete,
|
||||
|
@ -72,7 +76,38 @@ export const messageCreate: Event<typeof Events.MessageCreate> = {
|
|||
name: Events.MessageCreate,
|
||||
execute: async (message: Message) => {
|
||||
try {
|
||||
if (message.author.bot) return;
|
||||
if (message.author.bot || !message.guild) return;
|
||||
|
||||
const levelResult = await processMessage(message);
|
||||
const advancementsChannelId = loadConfig().channels.advancements;
|
||||
const advancementsChannel = message.guild?.channels.cache.get(
|
||||
advancementsChannelId,
|
||||
);
|
||||
|
||||
if (!advancementsChannel || !advancementsChannel.isTextBased()) {
|
||||
console.error(
|
||||
'Advancements channel not found or is not a text channel',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (levelResult?.leveledUp) {
|
||||
await advancementsChannel.send(
|
||||
`🎉 Congratulations <@${message.author.id}>! You've leveled up to **Level ${levelResult.newLevel}**!`,
|
||||
);
|
||||
|
||||
const assignedRole = await checkAndAssignLevelRoles(
|
||||
message.guild,
|
||||
message.author.id,
|
||||
levelResult.newLevel,
|
||||
);
|
||||
|
||||
if (assignedRole) {
|
||||
await advancementsChannel.send(
|
||||
`<@${message.author.id}> You've earned the <@&${assignedRole}> role!`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const countingChannelId = loadConfig().channels.counting;
|
||||
const countingChannel =
|
||||
|
@ -115,7 +150,7 @@ export const messageCreate: Event<typeof Events.MessageCreate> = {
|
|||
await message.react('❌');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error handling message create:', error);
|
||||
console.error('Error handling message create: ', error);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue