Use Red-DiscordBot to check if your server is online!


#1

As you know, going on the FiveM server browser just to see if your server/ another server is up is a pain sometimes, therefore i made this nice simple little script for people who use Red-DiscordBot on their Discord. How To Use: Simply create a .py file with any name you want and put it in the “cogs” folder of the bot, then copy this code in:

import discord
from discord.ext import commands
import socket
import requests
import aiohttp

servers = {
    "public" : 30120, # Add the port of the server and the name of it too!
}

class ServerCheck:
    """"IllusiveTea's Custom cog that checks if a server is up!"""
    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    async def ss(self, server):
        """Checks if a server is up \nServers:\npublic = Public server"""
        server = server.lower()

        port = 0

        try:
            port = servers[server]
        except KeyError:
            pass

        if port != 0:
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.settimeout(1)
            result = sock.connect_ex(("217.182.253.26", port))  #put your servers ip here!
            if result == 0:
                await self.bot.say("Server ``"+ server +"`` is Currently: __**Online!**__")
            else:
                await self.bot.say("Server ``"+ server +"`` is Currently: __**Offline**__. :frowning:")
            sock.close()
        else:
            await self.bot.say("Server ``" + server + "`` not found!")

def setup(bot):
    bot.add_cog(ServerCheck(bot))

MAKE SURE TO PUT YOUR SERVERS IP AND PORT IN THE PLACES SPECIFIED!

Then head into discord and do [p]load “Put Created file name here E.G: servercheck” ([p] is your command prefix, like mine is a “.”) then you’re set! Simply do [p]ss and it will respond depending on if it is or not!

Images! (The version on my server hence the message, but you can set to whatever you want!)

image
image


#2

Followed the steps exactly, and it gave me an error in discord when I was doing it. Said “script ran but something went wrong” nothing more:(


#3

Just updated the code, try that :stuck_out_tongue:


#4

Well my friend, I’m further ahead than I was before, but it always shows my server as offline :frowning:

I’ve tried the internet ip of the server, as well as the up on my home network.

Still at least recognizes the server which is a step forward aha.

Any ideas on the next steps I should follow? This will be great for my dev server for my team as I don’t always have it online.