---
source_url: https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/channels/references
title: Reference channels
updated_at: 2026-06-15T12:11:57.662Z
---

> Documentation Index
> For a curated overview of PubNub documentation, see: https://www.pubnub.com/docs/llms.txt
> For the full list of all documentation pages, see: https://www.pubnub.com/docs/llms-full.txt


# Reference channels

Channel referencing lets users mention channels in messages by typing `#` followed by at least three letters. Matching channel names appear as suggestions.

:::tip Generic referencing
Channel references, user mentions, and links are `MessageElement` instances with different `MentionTarget` types.
:::

Suggestions include all channels in the app keyset (up to 100), regardless of user membership. Configure up to 100 channel references per message (default: 10) and display them as links.

Implementation is similar to [user mentions](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/users/mentions) and [links](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/links).

:::note Requires App Context
Enable [App Context](https://youtu.be/9UEoSlngpYI) for your keyset in the [Admin Portal](https://admin.pubnub.com/).
:::

## Add channel references

Add channel references with `#` followed by at least three letters of the channel name (e.g., `#Sup`).

### Method signature

You can add a channel reference by calling the `AddMention()` method with the `target` of `MentionTarget.Channel`.

Refer to the [addMention()](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/drafts#add-message-element) method for details.

### Sample code

Create the `Hello Alex! I have sent you this link on the #offtopic channel.` message where `#offtopic` is a channel reference.

```csharp
using System.Linq;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;
// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
var channelResult = await chat.GetChannel("support");
if (channelResult.Error) return;
var testChannel = channelResult.Result;
        
// Create a message draft
var messageDraft = testChannel.CreateMessageDraft();

// Update the message with the initial text
messageDraft.Update("Hello Alex! I have sent you this link on the #offtopic channel.");

// Add a channel mention for the "#offtopic" channel
messageDraft.AddMention(45, 9, new MentionTarget
{
    Target = "group.offtopic", // Assuming the channel ID is "group.offtopic"
    Type = MentionType.Channel
});
```

## Remove channel references

`RemoveMention()` lets you remove a previously added channel reference from a [draft message](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/drafts).

### Method signature

You can remove channel references from a draft message by calling the `RemoveMention()` method at the exact offset where the channel reference starts.

Refer to the [RemoveMention()](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/drafts#remove-message-element) method for details.

:::warning Offset value
If you don't provide the position of the first character of the message element to remove, it isn't removed.
:::

### Sample code

Remove the channel reference from the `Hello Alex! I have sent you this link on the #offtopic channel.` message where `#offtopic` is a channel reference.

```csharp
using System.Linq;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;
// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
// assume the message reads
// Hello Alex! I have sent you this link on the #offtopic channel.

// Remove the channel reference for "#offtopic"
messageDraft.RemoveMention(45);
```

## Get channel suggestions

The event handler you attached to the `OnDraftUpdated` event returns all channels referenced in the [draft message](https://www.pubnub.com/docs/chat/unity-chat-sdk/learn/chat-entities/message-draft) that match the provided 3-letter string from your app's keyset.

##### Single listener

The event handler returns suggestions for channel references, user mentions, and links using `<List<MessageElement>` and `<List<SuggestedMention>`.

* `<List<MessageElement>` represent the draft's current state and can include plain text or links, such as user mentions, channel references, or URLs. These elements are organized to reflect their order in the draft.
* `<List<SuggestedMention>` provides potential mentions when available.

For example, if you type `#Sup`, you will get the list of channels starting with `Sup` like `Support` or `Support-Agents`. The default number of returned suggested channel names is `10`, configurable to a maximum value of `100`.

### Method signature

You must handle the event to update to the contents of a message draft, as well as retrieve the current message elements suggestions for user mentions, channel reference, and links. For example, when the message draft contains `... @name ...` or `... #chann ...`.

:::warning Enable receiving suggested mentions
You must enable receiving suggested mentions by setting `messageDraft.ShouldSearchForSuggestions = true;` before introducing your event handler.
:::

Refer to the [Add a message draft listener](https://www.pubnub.com/docs/chat/unity-chat-sdk/build/features/messages/drafts#add-message-draft-change-listener) section for details.

### Sample code

Insert the first suggested mention whenever the draft is updated and mentions are detected.

```csharp
using System.Linq;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;
// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
var channelResult = await chat.GetChannel("support");
if (channelResult.Error) return;
var channel = channelResult.Result;
        
var messageDraft = channel.CreateMessageDraft();

messageDraft.ShouldSearchForSuggestions = true;

messageDraft.OnDraftUpdated += (elements, mentions) =>
{
    if (!mentions.Any())
    {
        return;
    }
    messageDraft.InsertSuggestedMention(mentions[0], mentions[0].ReplaceTo);
};

messageDraft.Update("Alex are you a member of the #offtop channel?");
```

## Get referenced channels

You can access the `ReferencedChannels` property of the [Message object](https://www.pubnub.com/docs/chat/unity-chat-sdk/learn/chat-entities/message) to return all channel names referenced in a message.

### Method signature

This is how you can access the property:

```csharp
message.ReferencedChannels
```

#### Properties

| Property | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| ReferencedChannels | List<ReferencedChannel> | Optional |  | List of all channels referenced in a message. |

### Sample code

Check if the message with the `16200000000000000` timetoken contains any channel references.

```csharp
using System.Linq;
using System.Threading.Tasks;
using PubnubApi;
using PubnubChatApi;
using UnityEngine;
// Configuration
PubnubChatConfig chatConfig = new PubnubChatConfig();
        
PNConfiguration pnConfiguration = new PNConfiguration(new UserId("myUniqueUserId"))
{
    SubscribeKey = "demo",
    PublishKey = "demo",
    Secure = true
};

// Initialize Unity Chat
var chatResult = await UnityChat.CreateInstance(chatConfig, pnConfiguration);
if (!chatResult.Error)
{
    chat = chatResult.Result;
}
// reference the "support" channel
var channelResult = await chat.GetChannel("support");
if (!channelResult.Error)
{
    var channel = channelResult.Result;
    Debug.Log($"Found channel with name {channel.Name}");

    // get the message with the specified timetoken
    var messageResult = await channel.GetMessage("16200000000000000");
    if (!messageResult.Error)
    {
        var message = messageResult.Result;
        Debug.Log($"Message: {message.MessageText}");

        // check if the message contains any channel references
        if (message.ReferencedChannels != null && message.ReferencedChannels.Count > 0)
        {
            Debug.Log("The message contains channel references.");
            foreach (var referencedChannel in message.ReferencedChannels)
            {
                Debug.Log($"Referenced Channel: {referencedChannel.Name}");
            }
        }
        else
        {
            Debug.Log("The message does not contain any channel references.");
        }
    }
    else
    {
        Debug.Log("Message with the specified timetoken not found.");
    }
}
else
{
    Debug.Log("Support channel not found.");
}
```