How could I delete a message in roblox chat?

In my previous post or topic, I was wondering how I could edit a message in roblox studio, now what I want to know is how to delete a message, what I got is that in Chat > ChatScript > ChatMain > MessageLogDisplay, there’s a method called RemoveLastMessage and well… All I have for now is

Chat > ChatScript > ChatMain

EventFolder.DeleteMessageRequest.OnClientEvent:Connect(function(messageData)
	local channelObj = ChatWindow:GetChannel(messageData.OriginalChannel)
	
	if channelObj then
		channelObj:RemoveMessage(messageData)
		print(messageData.ID)
	end
end)

Chat > ChatScript > ChatMain > ChatChannel

function methods:RemoveMessage(messageData)
	table.remove(self.MessageLog, messageData.ID+2)
	
	if self.Active then
		self.MessageLogDisplay:RemoveMessage(messageData)
	end
end

Chat > ChatScript > ChatMain > MessageLogDisplay

function methods:RemoveMessage(messageData)
	self:WaitUntilParentedCorrectly()
	
	local Message = self.MessageObjectLog[messageData.ID+2]
	
	Message:Destroy()
	table.remove(self.MessageObjectLog, messageData.ID+2)
	
	self:ReorderAllMessages()
end

And well, It works fine but… sometimes the ID is wrong and doesnt delete the message or delete another message

So, can somebody help me, pleasee? I’ve read another topics in the forum, but I don’t think any of those works for what I want

Oh, I forgot, what I want is to make a music bot as discords bots and well, I got everything right, but what I want is, when a player sends the command “?play song’s name” it will sent 5 results and then the player has to select it sending the command “?play” and the number of the song, and when the player sends the command, the message that contains the command will be deleted and the message of the bot showing up the results will be edited by something like " “Song’s name” is added into the queue"

nvm, i got it. -----------------------------------------

Hey there,

Glad that you solved your problem on your own. However, It’d be very cool if you posted your solution here, in case anyone with the same problem comes across here.

Thanks!

2 Likes

Well, What I just did was

ChatScript > ChatMain > ChatChannel

function methods:RemoveMessage(messageData)
	local messageObject = nil
	local searchIndex = 1
	local searchTable = self.MessageLog

	while (#searchTable >= searchIndex) do
		local obj = searchTable[searchIndex]

		if obj.ID == messageData.ID then
			messageObject = obj
			break
		end

		searchIndex = searchIndex + 1
	end
	
	table.remove(self.MessageLog, searchIndex)
	
	if self.Active then
		self.MessageLogDisplay:RemoveMessage(messageData)
	end
end

ChatScript > ChatMain > MessageLogDisplay

function methods:RemoveMessage(messageData)
	local messageObject = nil
	local searchIndex = 1
	local searchTable = self.MessageObjectLog

	while (#searchTable >= searchIndex) do
		local obj = searchTable[searchIndex]

		if obj.ID == messageData.ID then
			messageObject = obj
			break
		end

		searchIndex = searchIndex + 1
	end

	if messageObject then
		messageObject:Destroy()
		table.remove(self.MessageObjectLog, searchIndex)
	end
end
3 Likes