Search code examples
herokudiscorddiscord.js

DISCORD.JS SendPing to Host


I'm developing a bot in Discord.js, and because I use lavalink, I hosted it (lavalink server) on a free host, and to keep it online I need to do some pings constantly, I was wondering if, is there any way to make my bot (which is currently my vps) send a ping every time interval to the "url/host" where my lavalink is. if you have any solution I will be grateful!


Solution

  • You have two ways:

    Using Uptimer Robot (fastest way)

    Uptimer Robot is an online service that can do HTTP requestes each 5 minutes. Very simple and fast to use, see more here.

    making the request from your bot vps

    Installing node-fetch

    Type this in yout terminal:

    npm i node-fetch
    

    Making the request

    Insert this where You want in the bot code.

    const fetch = require('node-fetch');
    const intervalTime = 300000; // Insert here the interval for doing the request in milliseconds, like now 300000 is equal to 5 minutes
    const lavalinkURL = 'insert here the lavalink process url';
    setInterval(() => {
        fetch(lavalinkURL);
    }, intervalTime)