getOrFail<T extends V> method

T getOrFail<T extends V>(
  1. K? key, {
  2. String? message,
})

Returns the value associated from the K parameter

Example :

Channel channel = guild.channels.cache.getOrFail('991686152585232404');
print(channel);

You can define an error customized message

Example :

Channel channel = guild.channels.cache.getOrFail('991686152585232404', message: 'Channel is undefined');
print(channel);

Implementation

T getOrFail<T extends V> (K? key, { String? message }) {
  final T? result = get(key);
  if (result == null) {
    throw NotExistException(message ?? 'No values are attached to $key key.');
  }

  return result;
}