Hello, I just got promoted to member a few days ago, ty god
I’m trying to modify a script that censors a mention for discord (yes I’m modifying a feedback script.)
I tried using string.gsub
this is my script I have tried so far…
Server:
local webhookURL = "https://discord.com/api/webhooks/(no u cant use my webhook)"
local filteringFunction = game.ReplicatedStorage.FilteringFunction
local ChatService = game:GetService("Chat")
local HTTP = game:GetService("HttpService")
function filteringFunction.OnServerInvoke(player, msg)
local Prevention = string.gsub(msg,"@everyone","[PREVENTION]") and string.gsub(msg,"@here","[PREVENTION]")
local FilteredMessage = ChatService:FilterStringForBroadcast(Prevention, player)
--Filter the message, before sending it to the webhook.
local payload = HTTP:JSONEncode({
content = FilteredMessage,
username = "From "..player.Name.." (UserId: "..player.UserId..")"
})
HTTP:PostAsync(webhookURL, payload)
return "Feedback recieved!"
end
no changes made for another script, but here
Client:
local maxCharacters = 500 -- Maximum Characters
local player = game.Players.LocalPlayer
local open = false
local feedbackMain = script.Parent.Frame
feedbackMain.MaxChar.Text = maxCharacters - #feedbackMain.Input.Text
feedbackMain.Input.Changed:Connect(function()
feedbackMain.MaxChar.Text = maxCharacters - #feedbackMain.Input.Text
end)
local db = false
feedbackMain.Submit.MouseButton1Click:Connect(function()
if not db and maxCharacters - #feedbackMain.Input.Text >= 0 then
db = true
local msg = feedbackMain.Input.Text
feedbackMain.Input.Text = "Sending Message..."
local response = game.ReplicatedStorage.FilteringFunction:InvokeServer(msg)
feedbackMain.Input.Text = response
wait(5)
if feedbackMain.Input.Text == response then
feedbackMain.Input.Text = ""
end
db = false
end
end)
Welcome to the Dev Forum! I hope you spend some quality time here!
The solution is rather simple. Take a look at the following.
local MENTIONS = {"@everyone", "@here"}
local message = "Hi @everyone!"
for i, phrase in pairs(MENTIONS) do
if (string.match(message, phrase)) then
print("REJECTED")
end
end
-- OUTPUT:
-->> REJECTED
However, you could also prevent any mentions this way:
local UNALLOWED = " @" -- white space before @
local message = "Hi @everyone!"
if (string.match(message, UNALLOWED)) then print("REJECTED") end
-- OUTPUT:
-->> REJECTED
Alternatively, you could replace @ character with your custom choice:
local UNALLOWED = " @" -- white space before @
local REPLACEMENT = " /"
local message = "Hi @everyone!"
message = message:gsub(UNALLOWED, REPLACEMENT)
print(message)
-- OUTPUT:
-->> Hi /everyone!
We are talking about help with censoring mention in a string that would be published to Discord. The third example (I have only looked on that one) provided by @EssenceExplorer won’t work in all cases (so it won’t always censor it).
You say that his and my remixed example would work the same.
And the answer is no because my example would replace all mentions and @EssenceExplorer’s - only when there is space in front of them. But the thing is that Discord interprets ‘Hello@everyone’ (without space) as mention too. That means that the 3rd example provided by Essence won’t work in all cases.
Also, you don’t need to filter text sent to non - Roblox websites. We all know this filter is a pain sometimes, but luckily Discord does not have this policy. (Since it’s 13+)
Thanks for the feedback. I didn’t know mention can be done without space. Anyways, @RocketB0ii can always set replacements and spaces customly. My intention was to provide universal pseudo code to give OP the idea on how it can be achieved.