Hosting discord bots WITHOUT 3rd party pinging services!!!
Hey there guys, many of us have made discord bot's BUT always have faced the problem that they didn't stay online...
So we had to get a million pinging services on them to keep them online... Not anymore!
We all probably already are in the habit of starting the webservers, and we need that, but no more pinging services!!!
If you don't know how to start a web server, see code below
from flask import Flask, render_template, redirect from threading import Thread app = Flask('') @app.route('/') def index(): return 'Bot is online!' def run(): app.run(host="0.0.0.0", port=8080) def webserver(): server = Thread(target=run) server.start() webserver()
So when you run your bot the first time with only this, the web server will open.
Now, if you don't have a
on_ready function already in your bot, you can make it simply by just pasting this line.
@client.event async def on_ready():
We now have our web server and our function, so what we do is add the following code to the imports and the
on_ready function and we are good to go!
# Imports import asyncio import requests # on_ready while not client.is_closed(): requests.get('') # put your server's link in here! await asyncio.sleep(30) # you can set any time, i prefer something in the range 30-60...
I'm hoping no issues arise with this, if they do, feel free to comment or DM me on discord, Sadashi#5058