getOr<T extends V?> method

T? getOr<T extends V?>(
  1. K? key, {
  2. T? defaultValue,
})

Returns the value associated from the K parameter or defined value

Example :

Channel firstChannel = guild.channels.cache.getOrFail('991686152585232404', defaultValue: myChannel );
Channel? secondChannel = guild.channels.cache.getOr('991686152585232404', defaultValue: firstChannel );
print(secondChannel);

Implementation

T? getOr<T extends V?> (K? key, { T? defaultValue }) {
  V? result = get(key);
  if (result == null) {
    return defaultValue;
  }

  return result as T?;
}