amount method

Future<void> amount(
  1. int amount, {
  2. String? reason,
})

Delete a specified amount of Message

Amount must be between 2 and 200.

Example :

final TextChannel channel = await guild.channels.resolve('240561194958716924');
await channel.bulkDelete.amount(100, reason: 'Too many messages in this channel');

Implementation

Future<void> amount(int amount, {String? reason}) async {
  if (amount >= maxMessages || amount <= minMessages) {
    return ioc.use<ConsoleService>().error('Provided too few or too many messages to delete. Must provide at least $minMessages and at most $maxMessages messages to delete. Action canceled');
  }

  if(_manager.cache.isEmpty || _manager.cache.length < amount) {
    await _manager.sync();
  }

  List<T> cache = _manager.cache.clone.values.toList();
  cache.sort((a, b) => a.createdAt.compareTo(b.createdAt));
  return messages(cache.reversed.take(amount).toList(), reason: reason);
}