I'm trying to create a discord bot using python to post my new IP address to discord whenever it changes. My intentions with the below code are that once started it should check the current IP address every minute to see if it has changed and then post the new IP address. However for testing I've removed a "not" so it should now post the message every minute until the IP address changes.
The problem is the bot is not sending any messages and giving any errors on the interpreter. Anyone got any ideas? (i'm an almost total novice to python so i really need instructions that include what code to add/change and where to add/change it)
import os
import discord
import socket
import asyncio
from discord.ext import tasks, commands
prefix = "!"
bot = commands.Bot(command_prefix=prefix)
from dotenv import load_dotenv
load_dotenv()
token = os.getenv('DISCORD_TOKEN')
Survival_Port = os.getenv('Survival_Port')
Creative_Port = os.getenv('Creative_Port')
Announcements_ID = os.getenv('Announcements_ID')
def Get_IP():
hostname = socket.gethostname()
IPAddress = socket.gethostbyname(hostname)
return IPAddress
@bot.event
async def on_ready():
print('Connected')
@tasks.loop(minutes=1)
async def IP_Address_Check():
if IPAddress==IPAddress0:
IPAddress0=Get_IP()
print(IPAddress0)
await announcements.send(f'New Server IP Address \n \n Survival Server: {IPAddress}:{Survival_Port} \n Creative Server: {IPAddress}:{Creative_Port}')
@IP_Address_Check.before_loop
async def wait_for_bot():
await bot.wait_until_ready
announcements = self.get_channel(Announcements_ID)
IPAddress=Get_IP()
print(IPAddress)
IP_Address_Check.start()
bot.run(token)
Thanks in advance