From 5ecb089a6ca487afbbd1023a0d4dd4a81054d574 Mon Sep 17 00:00:00 2001 From: Frostbide <129122542+Frostbide@users.noreply.github.com> Date: Sun, 25 May 2025 09:57:41 -0700 Subject: [PATCH] Add getmessages console command --- src/commands/console/getmessages.js | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/commands/console/getmessages.js diff --git a/src/commands/console/getmessages.js b/src/commands/console/getmessages.js new file mode 100644 index 0000000..c84f7cf --- /dev/null +++ b/src/commands/console/getmessages.js @@ -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)); + } + }, +};