How can i include the username of the replit user visiting the website?

How could I include the replit username of the website visitor into the script below? Also using this template. (There is already a login screen before this)

This is the script for the onload:

<body onload="sendMessage('{username}');">

This is the script for the webhook message:

function sendMessage(username) {
  const webhookUrl = '';
  const time = new Date();
  const jsonData = {
    "content": `${username} Visited the hh!`,
    "embeds": [
        "title": "Hiddenhub Visit",
        "description": `User: ${username}\nTime: ${time}`,
        "color": 1488863
    "username": "Visitbot9000",
    "avatar_url": "",
    "attachments": []

  const xhr = new XMLHttpRequest();'POST', webhookUrl);
  xhr.setRequestHeader('Content-Type', 'application/json');

You could probably use one of replit verification templates

1 Like

I am using one of the replit auth templates, and the user must login prior to this message being sent, but the name is still shown as {username}.

1 Like

Hmm, im not very experienced what to do with this, so maybe just try stack overflow or wait for someone else

1 Like

Also, change the category to coding help, in its respective language category as well

1 Like

Instead of this<body onload="sendMessage('{username}');"> use this <body onload="sendMessage(username);">

1 Like

This does not seem to work, as it just cancels out the message completely. Thank you for the response though!

1 Like

You have to pass the username to your template, line 27:

	return render_template('index.html', username=request.headers['X-Replit-User-Name'])

Then in your template:

<body onload="sendMessage('{{username}}');">

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