В синтезе мой код выглядит так:
Код: Выделить всё
class RoblinBot(commands.Bot):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.path = ".roblin"
self.fsettings = f"{self.path}/settings.json"
self.listen_urls = False
self.links = []
self.high_activity = False
self.setup()
def setup(self):
if not os.path.exists(self.path):
os.makedirs(self.path)
self.settings = Settings(self.fsettings)
def reset(self):
for f in os.listdir(self.path):
os.remove(os.path.join(self.path, f))
self.setup()
async def on_ready(self):
print("BOT READY")
try:
sync = await bot.tree.sync()
print(f"SYNCHED {len(sync)} COMMAND(S)")
await self.add_cog(ListenWebsite(self))
except Exception as e:
logger.exception(e)
Код: Выделить всё
class ListenWebsite(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.check_for_articles.start()
@tasks.loop(seconds=CHECK_EVERY)
async def check_for_articles(self):
print("this is a looped message")
if not self.listen_urls:
return
for url in self.settings.urls:
source = requests.get(url)
soup = BeautifulSoup(source.content, 'lxml')
raw = []
links = []
for link in soup.find_all('a', href=True):
raw.append(str(link.get('href')))
for item in raw:
match = re.search("(?Phttps?://[^\s]+)", item)
if match is not None:
links.append((match.group("url")))
links = list(set(links)) # remove duplicates
for link in links:
if link.count("-")
Подробнее здесь: [url]https://stackoverflow.com/questions/78698194/discord-py-task-function-has-no-attribute-start[/url]