Channel

A channel is a location where speakers can exchange messages, this page covers how to create them and their methods.

The default chat channel name is 'Main'.

The server API allows you to access channels and manage them from there.

local channelModule = api.channel --> {...}

Fetching Channels

--> :getByName(<string:name>)

This method fetches a channel by it's name, it will return nil if there's no channel found.

channel:getByName("Main") --> main chat

Creating a channel

--> .new(<string:name>,<boolean:autojoin>

This method creates a channel object with the specified name, and if it's marked as 'autojoin', speakers will automatically be assigned to it.

channel.new("Test",true) --> Channel named 'Test' that everyone is now assigned to.

Channel events, properties & methods

Properties

--> .name <string>

The '.name' property represents the channel's name.

channel.name --> <string>

--> .messageCount <integer>

The amount of messages in the channel thus far.

if(channel.messageCount > 100) then
    -- do something cool
end

--> .speakers <table>

The speakers associated with the channel in a table.

for _,speaker in pairs(channel.speakers) do
    print(speaker.name)
end

Events

--> .chatted <table:message>

This event is fired with a raw message object when a message is sent in the channel.

channel.events.chatted:Connect(function(object)
    print(object) --> {...} <message>
end)

--> .speakerAdded <table:speaker>

This event is fired when a speaker is added to the channel.

channel.events.speakerAdded:Connect(function(speaker)
    print(speaker.name,"is now in da club")
end)

--> .speakerRemoved <string:speakerName>

This event is fired when a speaker is removed from the channel.

channel.events.speakerRemoved:Connect(function(speaker)
    print("We didn't need",speaker.name,"anyways..")
end)

Methods

--> :registerMessageProcess(<string:name>,<function:callback>)

The function passed will be called with a message object twice (before filtering, and after filtering). You can make changes to the message before it's filtered to add data to the message or remove data.

-- This code works as-is and turns all messages sent in the 'Main' channel into a red 'quack'.

local channel = api.channel:getByName("Main")
channel:registerMessageProcess("Quackify",function(obj,filtered)
    if not filtered then
        obj.message = "quack"
        obj.data.chatColor = Color3.fromRGB(255,0,0)
    end
end)

--> :unregisterMessageProcess(<string:name>)

Was the quackify function too overpowered? We have the power to undo that now!

channel:unregisterMessageProcess("Quackify") --> quackify is no more!

--> :canSpeakerTalk(<table:speaker>) -> <boolean>

This method returns a boolean determining whether or not a speaker is in the specified channel.

if not channel:canSpeakerTalk(speaker) then
    print("rigged")
end

--> :sendMessage(<table:speaker>,<string:text>,(?<table:replyTo>)) --> <table:message>

This method is used internally from speaker:say(), and can be used as such:

local speaker = ...
local channel = ...

local msg = channel:sendMessage(speaker,"hi")
channel:sendMessage(speaker,"hello..",msg) --> Reply with "hello.."!

-->:editMessage(<integer:id>,<string:text>)

This method can be used to edit an existing message by ID.

local msg = channel:sendMessage(speaker,"hey")
local id = msg.data.id --> id specifically

channel:editMessage(id,"goodbye") --> (hey -> goodbye)

--> :getMessageById(<integer:id>)

This method can be used to fetch a message by it's ID.

local byId = channel:getMessageById(12) --> message with ID '12' if it exists in that channel

--> :Destroy(<void>)

This method destroys the channel and disconnects everything.

channel:Destroy()

Last updated