First post, sorry if a made any error. I'm trying to make a discord bot that notify in a group if a website HTML change but i don know how to make the bot send a message without any member online, i want to do an if(string:=string1): than send string1 to the group
import discord
from discord.ext import commands
client = discord.Client()
@client.event
async def on_ready():
print('Bot is ready.')
client.run('token')
Not quite sure what you mean by "if a website's HTML changes." Is this website on the same server that is hosting your discord bot? If so, you can do something like this:
import discord
import os
import asyncio
client = discord.Client()
@client.event
async def on_ready():
print('bot is ready.')
client.loop.create_task(checkHTML())
@client.event
async def checkHTML():
HTMLFileModificationTime = os.path.mtime('pathToHTMLFile')
if not os.path.exists("./lastModified.txt"):
with open("./lastModified.txt", "w") as fileN:
fileN.write(HTMLFileModificationTime)
pass
else:
with open("./lastModified.txt", "r") as fileN:
lastModified = fileN.read()
if HTMLFileModificationTime == lastModified:
pass # Not Modified
else:
with open("./lastModified.txt", "w") as fileN:
fileN.write(HTMLFileModificationTime)
for server in client.servers:
for channel in server.channels:
if channel.id == "CHANNEL ID HERE"
await client.send_message(channel, "MESSAGE HERE")
await asyncio.sleep(600)
client.run('token')
I'm at work currently, so I can't check to ensure that the above code will work "out of the box" but it's something I've used in a few bots in the past and should steer you in the right direction at least.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.