handleMessage method

Future<String?> handleMessage({
  1. required String message,
  2. required String userId,
  3. required String guildId,
  4. required String channelId,
  5. List<String> userRoles = const [],
})

Handle incoming message

Implementation

Future<String?> handleMessage({
  required String message,
  required String userId,
  required String guildId,
  required String channelId,
  List<String> userRoles = const [],
}) async {
  if (!message.startsWith(prefix)) return null;

  final parts = message.substring(prefix.length).split(' ');
  final commandName = parts[0].toLowerCase();
  final args = parts.skip(1).toList();

  final command = _commands[commandName];
  if (command == null) return null;

  // Check DJ mode
  if (djMode && command.requiresDJ) {
    if (!_hasDJRole(userRoles)) {
      return '❌ You need a DJ role to use this command!';
    }
  }

  final context = CommandContext(
    framework: this,
    userId: userId,
    guildId: guildId,
    channelId: channelId,
    args: args,
    userRoles: userRoles,
  );

  try {
    return await command.execute(context);
  } catch (e) {
    _eventController.add(CommandErrorEvent(commandName, e.toString()));
    return '❌ Error: $e';
  }
}