Add getmessages console command
This commit is contained in:
30
src/commands/console/getmessages.js
Normal file
30
src/commands/console/getmessages.js
Normal 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));
|
||||
}
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user