My discord bot code isn't working and no clue how to fix

Question: don’t now what I’m doing wrong

Repl link:

import discord
import requests
import asyncio

client = discord.Client()

@client.event
async def on_ready():
    print(f'We have logged in as {client.user}')

async def check_website():
    url = "https://www.servicepulse.org/"
    channel_id =
  1209508594156965908
# Replace with your channel ID
    channel = client.get_channel(channel_id)
    
    while True:
        try:
            response = requests.get(url)
            if response.status_code == 200:
                await channel.send(f"🟢 {url} is up and running!")
            else:
                await channel.send(f"🔴 {url} is down! Status code: {response.status_code}")
        except Exception as e:
            await channel.send(f"❌ Error checking {url}: {e}")
            
        await asyncio.sleep(60)  # Check every 60 seconds

client.loop.create_task(check_website())
client.run('REDACTED - CHANGE ASAP')

I think you have intended to pass the method reference, not call the method.
check_website() should be check_website, the difference is that the first invokes it while the 2nd passes the method itself.

4 Likes

Please do not put your Discord API key in the code snippet, instead use Replit Secrets.

4 Likes

What exactly isn’t working?