imvumafia chat logger - Discord Webhook

Toolyx
by Toolyx · 3 posts
1 year ago in Javascript
Posted 1 year ago · Author
Code
const webhookURL = "Your Discord Webhook";

// Initialize variables
let lastMessage = "";
let sentMessages = new Set();

// Function to send message to webhook
async function sendToWebhook(data) {
    // Send message to webhook
    const response = await fetch(webhookURL, {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify(data),
    });

    if (!response.ok) {
        throw new Error(`Failed to send data to webhook: ${response.status}`);
    }
}

// Function to listen for new messages
function listen() {
    let els = document.querySelectorAll(".mChatMessageRow");
    if (els.length > 0) {
        els.forEach((el) => {
            let message = el.querySelector(".mChatMessage").textContent.trim();
            let username = el.querySelector(".mChatMessage a").textContent.trim();
            let avatar = el.querySelector(".mChatAvatar img").getAttribute("src");

            if (lastMessage !== message) {
                lastMessage = message;
                if (!sentMessages.has(message)) {
                    sentMessages.add(message);
                    // remove spaces from message
                    message = message.replace(/\s/g, "");
               
                   
                    sendToWebhook({
                        content: message,

                    });
                    console.log(message, username, avatar);
                }
            }
        });
    }
    setTimeout(listen, 1000);
}

// Start listening for new messages
listen();



Just for fun, not meant to be great, lol.

This code is for a Discord webhook that logs the IMVU Mafias mchat shoutbox.

Navigate to the server you want to create the webhook on.

Click on the server settings button, which is represented by a gear icon.

In the server settings, navigate to the "Webhooks" tab.

Click on the "Create Webhook" button.

Click the "copy webhook URL" button to get your webhook's auth token.

Copy your token and place it where it says (YOUR WEBHOOK URL!) into the script.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Sign in

Already have an account? Sign in here

SIGN IN NOW

Create an account

Sign up for a new account in our community. It's easy!

REGISTER A NEW ACCOUNT