Ad
Log in to vote
0

Discord Chat Log Script - How do i get the message to also include the roblox username?

Asked by 1 month ago
Edited 1 month ago

I have this script for chat log for Discord, it is working fine but the problem is that i want the username to be put with the message. Right now, the username is being put as the Bots name - i dont mind keeping it like that, i just want the username also in the discord message along with the roblox message. For example, The message i would want the bot to send could be e.g) Roblox: Hi instead of just Hi or e.g) Roblox Hi

Any help is appreciated.

(Also I removed the web hook link for the sake of the post and im fine with completely swapping this code with a different one if it does what im asking for)

local https = game:GetService("HttpService")

local webhook = "PUT WEBHOOK LINK HERE"


function sendDiscordMessage(message, name, picture)

    local info = {
        content = message,
        username = name,
        avatar_url = picture
    }

    local encoded = https:JSONEncode(info)

    https:PostAsync(webhook, encoded)
end


game.Players.PlayerAdded:Connect(function(player)

    local name = player.DisplayName .. " (@" .. player.Name .. ")"

    local imageUrl = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&Type=AvatarHeadShot&userId=" .. player.UserId

    player.Chatted:Connect(function(message)


        sendDiscordMessage(message, name, imageUrl)
    end)
end)

1 answer

Log in to vote
0
Answered by
qfoxb 26
1 month ago
Edited 1 month ago

Not sure if discord allows you to log chats like that, but you'd want to change content = message to content = name..":"..message to attach the name

Here's the code Also, you can change the : to anything you want.

local https = game:GetService("HttpService")

local webhook = "PUT WEBHOOK LINK HERE"


function sendDiscordMessage(message, name, picture)

    local info = {
        content = name..": "..message,
        username = name,
        avatar_url = picture
    }

    local encoded = https:JSONEncode(info)

    https:PostAsync(webhook, encoded)
end


game.Players.PlayerAdded:Connect(function(player)

    local name = player.DisplayName .. " (@" .. player.Name .. ")"

    local imageUrl = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&Type=AvatarHeadShot&userId=" .. player.UserId

    player.Chatted:Connect(function(message)


        sendDiscordMessage(message, name, imageUrl)
    end)
end)
0
Thank you! It works great :) lukepillingrblx 2 — 1mo
Ad

Answer this question