Interface MessageChannelUnion

All Superinterfaces:
Channel, Formattable, IMentionable, ISnowflake, MessageChannel

public interface MessageChannelUnion extends MessageChannel
A union representing all channel types that implement MessageChannel.
This class extends MessageChannel and primarily acts as a discovery tool for developers to discover some common interfaces that a MessageChannel could be cast to.
This interface represents the follow concrete channel types:
  • Method Details

    • asPrivateChannel

      @Nonnull PrivateChannel asPrivateChannel()
      Casts this union to a PrivateChannel. This method exists for developer discoverability. Note: This is effectively equivalent to using the cast operator:
      
       //These are the same!
       PrivateChannel channel = union.asPrivateChannel();
       PrivateChannel channel2 = (PrivateChannel) union;
       
      You can use Channel.getType() to see if the channel is of type ChannelType.PRIVATE to validate whether you can call this method in addition to normal instanceof checks: channel instanceof PrivateChannel
      Returns:
      The channel as a PrivateChannel
      Throws:
      IllegalStateException - If the channel represented by this union is not actually a PrivateChannel.
    • asTextChannel

      @Nonnull TextChannel asTextChannel()
      Casts this union to a TextChannel. This method exists for developer discoverability. Note: This is effectively equivalent to using the cast operator:
      
       //These are the same!
       TextChannel channel = union.asTextChannel();
       TextChannel channel2 = (TextChannel) union;
       
      You can use Channel.getType() to see if the channel is of type ChannelType.TEXT to validate whether you can call this method in addition to normal instanceof checks: channel instanceof TextChannel
      Returns:
      The channel as a TextChannel
      Throws:
      IllegalStateException - If the channel represented by this union is not actually a TextChannel.
    • asNewsChannel

      @Nonnull NewsChannel asNewsChannel()
      Casts this union to a NewsChannel. This method exists for developer discoverability. Note: This is effectively equivalent to using the cast operator:
      
       //These are the same!
       NewsChannel channel = union.asNewsChannel();
       NewsChannel channel2 = (NewsChannel) union;
       
      You can use Channel.getType() to see if the channel is of type ChannelType.NEWS to validate whether you can call this method in addition to normal instanceof checks: channel instanceof NewsChannel
      Returns:
      The channel as a NewsChannel
      Throws:
      IllegalStateException - If the channel represented by this union is not actually a NewsChannel.
    • asThreadChannel

      @Nonnull ThreadChannel asThreadChannel()
      Casts this union to a ThreadChannel. This method exists for developer discoverability. Note: This is effectively equivalent to using the cast operator:
      
       //These are the same!
       ThreadChannel channel = union.asThreadChannel();
       ThreadChannel channel2 = (ThreadChannel) union;
       
      You can use Channel.getType().isThread() to validate whether you can call this method in addition to normal instanceof checks: channel instanceof ThreadChannel
      Returns:
      The channel as a ThreadChannel
      Throws:
      IllegalStateException - If the channel represented by this union is not actually a ThreadChannel.
    • asVoiceChannel

      @Nonnull VoiceChannel asVoiceChannel()
      Casts this union to a VoiceChannel. This method exists for developer discoverability. Note: This is effectively equivalent to using the cast operator:
      
       //These are the same!
       VoiceChannel channel = union.asVoiceChannel();
       VoiceChannel channel2 = (VoiceChannel) union;
       
      You can use Channel.getType() to see if the channel is of type ChannelType.VOICE to validate whether you can call this method in addition to normal instanceof checks: channel instanceof VoiceChannel
      Returns:
      The channel as a VoiceChannel
      Throws:
      IllegalStateException - If the channel represented by this union is not actually a VoiceChannel.
    • asThreadContainer

      @Nonnull IThreadContainer asThreadContainer()
      Casts this union to a IThreadContainer. This method exists for developer discoverability. Note: This is effectively equivalent to using the cast operator:
      
       //These are the same!
       IThreadContainer channel = union.asThreadContainer();
       IThreadContainer channel2 = (IThreadContainer) union;
       
      You can use channel instanceof IThreadContainer to validate whether you can call this method.
      Returns:
      The channel as a IThreadContainer
      Throws:
      IllegalStateException - If the channel represented by this union is not actually a IThreadContainer.
    • asGuildMessageChannel

      @Nonnull GuildMessageChannel asGuildMessageChannel()
      Casts this union to a GuildMessageChannel.
      This works for the following channel types represented by this union: Note: This is effectively equivalent to using the cast operator:
      
       //These are the same!
       GuildMessageChannel channel = union.asGuildMessageChannel();
       GuildMessageChannel channel2 = (GuildMessageChannel) union;
       
      You can use Channel.getType().isGuild() to validate whether you can call this method in addition to normal instanceof checks: channel instanceof GuildMessageChannel
      Returns:
      The channel as a GuildMessageChannel
      Throws:
      IllegalStateException - If the channel represented by this union is not actually a GuildMessageChannel.