Add getmessages console command

This commit is contained in:
Frostbide
2025-05-25 09:57:41 -07:00
parent ad96f6358c
commit 5ecb089a6c

View File

@@ -0,0 +1,30 @@
const chalk = require('chalk');
module.exports = {
names: ['getmessages'],
async run(context) {
const { bot, args } = context;
const { client } = bot;
const [channelId, amount] = args;
const channel = await client.channels.fetch(channelId);
if (!channel?.isTextBased?.()) {
bot.logger.log(chalk.red('Channel not found or not a text channel.'));
return;
}
try {
const messages = await channel.messages.fetch({ limit: amount });
messages.reverse();
messages.forEach((message) => {
const logMessage =
bot.events.loggingMessages.messageCreateHandlers[message.type];
if (logMessage) return logMessage(message);
bot.events.loggingMessages.messageCreateHandlers[0](message);
});
} catch (err) {
bot.logger.log(chalk.red(err));
}
},
};