2

I have just started to code in javascript yesterday and I am trying to code a bot for Discord. Basically, I am making a command that says "show me _______" and it will generate a link based on the input. Then I need it to check if that url actually exists before sending it in the Discord chat. If that url does not exist it will send the person a WIKI page on another site with the information asked of. I need help with figuring out how to check if the URL works assuming I only have discord.js installed. Do I have to install something else? After installing, how would I go about coding it?

I have tried code suggestions I found browsing the web and none of them work without the bot crashing the moment the function is called. I believe it is because I do not have something installed. From further research I think I might need Ajax?

if (message.content.startsWith(`${prefix}show me`)) {

    var site;
    site = "http://www.transformersworld.dx.am/Characters/" + message.content.substring(22).toLowerCase() + ".html"

    var request;
    if (window.XMLHttpRequest)
        request = new XMLHttpRequest();
    else
        request = new ActiveXObject("Microsoft.XMLHTTP");
    request.open('GET', site, false);
    request.send(); // there will be a 'pause' here until the response to come.
    // the object request will be actually modified
    if (request.status === 404) {
        message.channel.send("The page you are trying to reach is not available.");
    }
                message.channel.send("http://www.transformersworld.dx.am/Characters/" + message.content.substring(22).toLowerCase() + ".html");








}

When I type this into visual studio, it does not autocomplete/recognize the command XMLHttpRequest(). Do I need AJAX? How do I get it? I have nodejs so I could use that to install it if I knew how.

EDIT: I have the AJAX toolkit but I get an error when I run the program. Does anyone know what I should replace window with or how to fix it?enter image description here

EDIT2: I have no clue what to do. It doesn't recognise XMLHttpRequest. enter image description here

0 Answers0