Missing method "Connect" with custom chat system's API


Table doesn’t have any contents apparently and then comes the “Missing method” thing again… Does that mean stuff from the module is not being inserted into the table or something like that?

1 Like

A:

I believe this error means that the speaker object was not defined inside of the scope.
In order to solve it, you will need to pass the speaker object into the callback function.
function on_speaker_set(speaker)
local message = "Speaker set to " … speaker.Name
Chat:Chat(message)
end

Chat:RegisterCommand(“speaker”, {
– …
Callback = on_speaker_set,
– …
})

Again, this is NOT the default Roblox chat. This is a custom chat with it’s own, custom and independent API, so your code will not work.

Please check out the actual module and the API’s documentation that I provided in the main post so that you can actually understand what the issue is.

1 Like

You still dont know what you want yourself we cannot help

Yes, I do! Read my post so you can actually help me or just don’t bother replying! I want to make a custom command in the server using the server api. That’s what I need to do. But the :Connect method is missing from the speakerAdded function that detects when the player sends a message, so the command does not work! Do you understand now?

There is someone else trying to ACTUALLY help me right now, and by arguing here we are flooding the topic. Are you going to actually try to help or are you going to keep posting unrelated answers?

1 Like

@BendsSpace Sorry for all the arguing in this topic lol, here’s what the Studio output says when printing out api.speaker, the table is apparently empty

I’m reading the code. The person who made this wrapped the table with a meta table in a weird way that makes it super hard to debug (they did it only so people can use what ever casing like CONNECT, Connect, or connect).

I think the person who made the chat has a bug in their code, I removed the (smart but kind of bothersome) wrapping code and it seems to work.

Where’s the wrapping code located at? I’ll try to remove it and see if it works (I’m not too experienced with tables so I really just don’t know how wrapping works lol)

It basically just changes how the table looks for values.

More detailed explaination

__index is a meta table index that determines how the table looks for values based on the index when the index isn’t in the table. The wrap code creates a new blank table and sets the __index to a function that uses the index to look through the original table.

The wrapping code is betterchat_shared.wrap. You can disable it by changing line 36 of MainModule to

local wrap = function(a) return a end -- Instead of wrapping and returning it just skips wrapping.

Edit:

I tested that and it seemed to solve the problem (the code printed when the player chatted using your code above. There are some data store warnings in the logs but I assume those are because I didn’t enabled datastores).

2 Likes

Thank you so much, I can’t believe it was so simple to fix!

1 Like

Yeah, that’s almost certainly a bug in the custom chat. Good luck with your custom commands!

1 Like

Hey, this is a bit random, but I wanted to know if you knew how I could solve this other issue related to the chat since you were able to figure out the previous issue so quickly…

image
I’m testing my ban command now that commands actually work, which is supposed to send a message saying “(mod name) has banned (banned player) for (reason)”. Right now I was testing the first part of the message but when the message is sent, it also has a bunch of underscores (which is the default character when a message is being reviewed by the chat’s filter before either sending it or turning it into hashtags), which is extremely annoying and I just can’t figure out how to stop it from happening.

This also happens sometimes when the player sends a message, if they spam something, sometimes an (extra) underscore is sent alongside the message itself, and sometimes straight up overrides the message
image

(I also wanna let you know that I modified 2 scripts in the main module, one so that if a message starts with / it doesn’t actually show up in the chat, so that the player only sees the actual command message and not the /command thing they typed, and the other so if a speaker’s name is just a string with nothing on it (""), it doesn’t show the : that appear when someone sends a message, like playername: text, which is why the ban command message was shown like that. it doesn’t really affect the thing as even without the 2 modifications the error was still happening, but just thought i should probably mention it.

This is the code inside the Addons folder > Server folder > CommandHandler module script

return function(api)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ServerScriptService = game:GetService("ServerScriptService")
local CommandRemote = ReplicatedStorage.begincmd

local player = ServerScriptService.retrieveplayerfromserver:Invoke()
local ids = ServerScriptService.whitelistedids:Invoke()


CommandRemote.OnServerEvent:Connect(function(player2, message)
	if player2 == player then
		if table.find(ids, player.UserId) then
			
			
			
			
			------------[[/////////////  COMMANDS     \\\\\\\\\\\\\\\\\\\]]----------
			
			if message == "/ban" then
				
				
				
				
				local _,newSpeak = api.speaker.new("")


				local moderatorNameRgb = game.Players[player.Name]:GetAttribute("DisplayNameColor")
				local R1 = moderatorNameRgb.R * 255
				local G1 = moderatorNameRgb.G * 255
				local B1 = moderatorNameRgb.B * 255

				local newmessage = newSpeak:say("Main","(".. R1 ..",".. G1 ..",".. B1 .." / ".. player.Name ..") has banned ")
				--Color3.fromRGB()
				
				
				newSpeak:Destroy()
				
				
				
			end
			
			
			
			
			
			
			
			
			
			
			
		end
	end
end)






--[[]
api.speaker.speakerAdded:Connect(function(speaker)
	speaker.events.chatted:Connect(function(message,messageObject)
		local player = messageObject.sender
		
		--[[]
		
		local playerGui = player.PlayerGui
		local Chat = playerGui.Chat
		local Container = Chat.Container
		local main = Container.ChatWindow.Main
		local MessageContainer = main.Scroller.MessageContainer
		MessageContainer.ChildAdded:Connect(function(child)
			if child:IsA("Frame") then
				local Raw = child:WaitForChild("Raw")
				if string.find(Raw:WaitForChild("User").Text, player.DisplayName) then

					child:Destroy()

				end
			end
		end) --]]

--[[]
		

		if(message:sub(1,1) == "/") then

			--messageObject:Destroy()
			


			if message == "/ban" then



			else

				local _,newSpeak = api.speaker.new("")


				local moderatorNameRgb = game.Players[speaker.name]:GetAttribute("DisplayNameColor")
				local R1 = moderatorNameRgb.R * 255
				local G1 = moderatorNameRgb.G * 255
				local B1 = moderatorNameRgb.B * 255

				local newmessage = newSpeak:say("Main","(".. R1 ..",".. G1 ..",".. B1 .." / ".. speaker.name ..") has banned ")
				--Color3.fromRGB()

			end





		end
	end)


end)--]]

end


it works fine, but as shown in the screenshot the extra message made up entirely of underscores still appear…

Again, sorry for the random question, I just don’t think I should make an entirely new topic for something that’s so related to my last one and is probably gonna have a very silly solution like the last problem and I thought I should ask you as you were able to help me fix my previous issue so fast :P.

I’m not sure why that is happening, you might be able to use Channel:editMessage or Channel:registerMessageProcess to reset the messages so the filtering doesn’t affect them. It’s weird better chat doesn’t have a way to display an unfiltered message.

It could also be that you need to set Speaker.IsPlayer to false. I don’t know why better chat would filter non-player messages.

Hey! Sorry for the late response

Would something like this help? It doesn’t give off any errors but it doesn’t do anything either…

1 Like

I don’t think it would work like that. It’s possible code that reads the unfiltered message, waits for the next event (after the filtering) and resets the obj.message back to the stored unfiltered message would work.

I found the API that’s meant to do this, api:systemMessage(). It forces there to be "Server: " in front though. There might be a way to change that, I’m not sure.

Yeah, the problem with api:systemMessage() is that it only works with the client according to the docs and I need the ban message to work for everyone but then again I can just FireAllClients() so that everyone in the server sees the message. I was planning on making some kind of “talk” command that sends a message with another player’s name, but I guess I’ll try to modify api:systemMessage() so that it has some extra parameters and maybe I can make something like that using the same systemMessage() method.

I guess I could also try to see what registerMessageProcess does and see if I can make it fire a bindable function or something during filtering, so if the message is a command found in the command table I’ll make later then it’s not filtered and just runs through. Dunno if that’s against the TOS though as it’s modifying the filtering system in some way. I don’t think I’d be in trouble though, as the messages don’t contain anything inappropriate, and doing that would save me a bunch of trouble as I find the “speaker” stuff much more customizable than just doing “systemMessage”

1 Like

Hey, one last question… I figured out a “way” to do this whole thing which actually works but there’s one last issue, apparently with the “DisplayOrder” thing.

When the command is sent, the custom message is also sent but appears on top of every other message, and it’s because of the DisplayOrder… how would i make it so it shows up normally? I think I saw something regarding DisplayOrder inside of the actual System messages module in the chat’s MainModule, but I don’t really get it
image

(this is the System Message module i’m talking about;


)

The code means:

local result

if order then
    result = order
else if queue[1] then
    result = queue[1].LayoutOrder
else
    result = 0
end

object.LayoutOrder = result

You can probably ignore the order parameter and look for the queue object. It’s probably in the script that requires the system message module.

The problem is, I’m using a separate script for this thing (Basically, from the server (The command handler module) I fire a bindable event that is triggered inside of a script in SSS, with this function;

and in the client, when the event is fired, it uses the same modulescripts used by the actual system (I just copied them from the system and pasted them inside of the localscript) to create a chat message frame gui object, and sets its parent to the chat’s message container frame; so I don’t know how i’d be able to get the queue object in that local script…

local ReplicatedStorage = game:GetService("ReplicatedStorage")

wait(1)

local remote = ReplicatedStorage:FindFirstChild("MakeChatMessage")

local bind = ReplicatedStorage:FindFirstChild("Bind_MakeChatMessage")

local regular = require(script.regular)

local rich = require(script.richText)

local player = game.Players.LocalPlayer

local chat = player.PlayerGui:WaitForChild("Chat")

local main = chat.Container.ChatWindow.Main

local msgContainer = main.Scroller.MessageContainer

remote.OnClientEvent:Connect(function(speaker, message, color, hasDots)

local object = regular.new()

local message = rich:escape(message)

if speaker == "" then

object.Raw.Text = message

else

object.Raw.Text = ("%s %s"):format(rich:colorize(speaker .. ":",color),message) or message

end

--object.Raw.Text = speaker ~= "" and ("%s %s"):format(rich:colorize(speaker .. ":",Color3.fromRGB(200,200,200)),message) or message

--object.Parent = scroller

object.Parent = msgContainer

--object.LayoutOrder = order and order or (queue[1] and queue[1].LayoutOrder or 0)

end)

(ignore the comments in the script)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.