Created
June 21, 2021 07:33
-
-
Save NullCode1337/e8e8aeb72dd707eface4b7fc8133f168 to your computer and use it in GitHub Desktop.
Make discord.py bot run ONLY after internet connection is validated
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Only tested on Windows 10 | |
# ------------------------- | |
# Here is a basic discord.py bot | |
import discord | |
from discord.ext import commands | |
from socket import create_connection | |
client = commands.Bot(command_prefix = "your prefix") | |
token = "bot token" | |
@client.event | |
async def on_ready(): | |
print("Bot ready") | |
# Actual internet part starts from here | |
def is_connected(): | |
try: | |
create_connection(("1.1.1.1", 53)) | |
return True | |
except OSError: | |
pass | |
return False | |
while is_connected() == False: print("No internet"); print() # You can change this out for something else | |
client.run(token) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Extended description:
This is a VERY barebones discord.py rewrite bot that will only run once there is an internet connection present
Useful if you want to run bot on computer startup and there's no internet for the first n seconds