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!)