Skip to content

Instantly share code, notes, and snippets.

@NullCode1337
Created June 21, 2021 07:33
Show Gist options
  • Save NullCode1337/e8e8aeb72dd707eface4b7fc8133f168 to your computer and use it in GitHub Desktop.
Save NullCode1337/e8e8aeb72dd707eface4b7fc8133f168 to your computer and use it in GitHub Desktop.
Make discord.py bot run ONLY after internet connection is validated
# 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)
@NullCode1337
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment