> For the complete documentation index, see [llms.txt](https://jumpathy.gitbook.io/betterchat-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jumpathy.gitbook.io/betterchat-documentation/plugin-api/server/channel-object.md).

# Channel Object

### Methods

#### getHistory

```lua
local channel = API.channel.cache("testing channel")
local channelHistory = channel:getHistory()
```

This function will return the channel's message history. Messages can only be added to the channels using the "***addMessage***" function.

**getHistoryForUser**

```lua
local player = game.Players.Player1
local channel = API.channel.cache("testing channel")
local channelHistoryForUser = channel:getHistoryForUser(player.UserId)
```

This function will return the channel's filtered message history. When a message is generally sent, it's filtered differently for each user. This also follows the same rule and filters the message history for the specific user that you request.

| Type   | Name   |
| ------ | ------ |
| number | userid |

#### addMessage

{% hint style="danger" %}
If the speaker sending the messages is not a player, the messages will not filter.
{% endhint %}

```lua
local channelName = "all" --> Specified channel name
local speaker = API.speaker.cache("Player1",false) --> Get speaker for "Player1"
local channel = API.channel.cache(channelName) --> Get channel for "all"
channel:addSpeaker(speaker) --> Add the speaker to channel "all"

local arguments = {
	 "Player1", --> Speaker name
	 "Message", --> Speaker message
	 channelName, --> Channel name
	 nil, --> Speaker's player object (used for filtering + other things)
	 "default" --> Message type (do not change)
}

local success,result = API.chatSystem:createMessageObject(unpack(arguments)) --> Create the message object

if(success) then
	  channel:addMessage(result,true) --> Add the message and make all players in the channel see it with "true"
else
	  warn("[BETTER CHAT ERROR]:",result) --> Notify of errors that occured when making the message
end
```

<div align="left"><img src="/files/-MVHpgALqWY8C33P_Dpo" alt=""></div>

This method will add a message to the chat's history. If you add a "true" value to it, it'll make the message display in all connected user's chats.

| Type                 | Name              |
| -------------------- | ----------------- |
| message (dictionary) | message object    |
| boolean              | replicate message |

#### isSpeakerInChannel

```lua
local chatChannel = API.channel.cache("all")
local speaker = API.speaker.cache("Player1")
local isPlayerInChannel = chatChannel:isSpeakerInChannel(speaker)
print(isPlayerInChannel)
```

This method will return if the specified speaker is in the specific chat channel.

| Type                 | Name    |
| -------------------- | ------- |
| speaker (dictionary) | speaker |

#### getSpeakers

```lua
local chatChannel = API.channel.cache("all")
local speakersList = chatChannel:getSpeakers()
print(speakersList)
```

This method will return a table of **players** who are in the specified channel.

#### addSpeaker

```lua
local channelName = "all"
local speaker = API.speaker.cache("Player1",false)
local channel = API.channel.cache(channelName)
channel:addSpeaker(speaker)
```

This method will add the specified speaker to the specified channel.&#x20;

| Type                 | Name    |
| -------------------- | ------- |
| speaker (dictionary) | speaker |

#### removeSpeaker

```lua
local channelName = "all"
local speaker = API.speaker.cache("Player1",false)
local channel = API.channel.cache(channelName)
channel:addSpeaker(speaker)
wait(1)
channel:removeSpeaker(speaker)
```

This method will remove the specified speaker from the specified channel.

| Type                 | Name    |
| -------------------- | ------- |
| speaker (dictionary) | speaker |
