My If-Statement should prevent something, but does not prevent something

  1. What do you want to achieve? I want to make that chatlogs do not process [at]everyone and [at]here.

  2. What is the issue? The chatlogs do process these two blacklisted words. How can I fix that?

  3. What solutions have you tried so far? I have tried ~= and if not msg == ‘[at] everyone’ then. None of then worked.

Everytime I wrote any of these 2 blacklisted words into the chat, it still got these onto discord.

This is my code:

local Players = game:GetService("Players")
local HttpService = game:GetService("HttpService")

local webhook = "https://discordapp.com/api/webhooks/"   --Just change this link tot he one generated when setting up the webhook on discord.
local reboot = "https://discordapp.com/api/webhooks/"

Players.PlayerAdded:Connect(function(plr)
 plr.Chatted:Connect(function(msg)
  local data = {
   content = msg;
   username = plr.Name;
   avatar_url = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&username="..plr.Name
          }
        if data.content ~= '@everyone' or data.content ~= '@here' then
              HttpService:PostAsync(webhook, HttpService:JSONEncode(data))
        else
            print('it is the everyone or here')
        end
 end)
end)

I’m not sure you should do chat logs this way, the http request limit is 500 requests per minute…
Note that discord’s limit is 30 requests per minute.

Please note that Discord is not meant for chat logging. Coding wise though, there are a few solutions. That only checks if it is just ‘@everyone’ and that alone. If there is any text followed after it, it will not be detected. If you would like to remove that, you can surround your message with grave accents. Here:

content = "`"..msg.."`"

So that pings will not work. Another alternative is to use string.find().

if not string.find(msg,"@everyone") and not string.find(msg,"@here") then
1 Like

Someone could just make their message be “`@everyone`” and it’d ping. That’s not a good solution. A better option is using an actual embed.

2 Likes

Or to do something like content:gsub("@", "")

1 Like

@posatta
@deprecatedHeart

Can’t you just use string.sub() and check if the first characters required are equal?

if string.sub(data.content, 1, 9) == "@everyone" then
    —bla bla bla
end

if string.sub(data.content, 1, 5) == "@here" then
    —bla bla bla
end

No? If this is user-generated, the user isn’t going to be nice enough to start the message with @everyone for you. He’s trying to avoid the message from having pings in it.

2 Likes

Oh wait I didn’t even read the post I was just looking at the replies, I thought he was just trying to detect if a message had @everyone or @here in it