Как зациклить работу бота на Discord.py?
Проблема в том что после выполнения условия срабатывает bot.run() после которого цикл не перезапускается. Я впервые работаю с этой библиотекой, простите.
from numpy import repeat
import requests
import re
import asyncio
import config
from bs4 import BeautifulSoup
from discord.ext import commands
bot = discord.Client()
news = "https://stopgame.ru"
while True:
req = requests.get("https://stopgame.ru/news")
src = req.text
soup = BeautifulSoup(src)
post = soup.find("a", class_='article-image')
url = post.get('href')
print(url)
req = requests.get("https://stopgame.ru" + url)
src = req.text
soup = BeautifulSoup(src)
news_content = soup.find('div', class_='_content-wrapper_10acs_23 _text_10acs_498 _first-wrapper_10acs_541')
print(news_content.text)
with open('last_url.txt', 'r') as file:
read_url = file.read()
if read_url != url:
last_url = open("last_url.txt", "w")
last_url.write(url)
last_url.close()
@bot.event
async def on_ready():
channel = bot.get_channel(ид канала)
await channel.send(news_content.text)
await channel.send("Оригинал новости " + "https://stopgame.ru"+ url)
bot.run(config.settings['токен'])```
Ответы (1 шт):
Автор решения: The1ODDme
→ Ссылка
Нашел ошибку, вот рабочий код если кому будет нужно.
import discord
from numpy import repeat
import requests
import re
import asyncio
import config
from bs4 import BeautifulSoup
from aiogram import Bot, Dispatcher, executor, types, filters
from discord.ext import commands
bot = discord.Client()
news = "https://stopgame.ru"
@bot.event
async def on_ready():
while True:
req = requests.get("https://stopgame.ru/news")
src = req.text
soup = BeautifulSoup(src)
post = soup.find("a", class_='article-image')
url = post.get('href')
print(url)
req = requests.get("https://stopgame.ru" + url)
src = req.text
soup = BeautifulSoup(src)
news_content = soup.find('div', class_='_content-wrapper_10acs_23 _text_10acs_498 _first-wrapper_10acs_541')
with open('last_url.txt', 'r') as file:
read_url = file.read()
if read_url != url:
last_url = open("last_url.txt", "w")
last_url.write(url)
last_url.close()
channel = bot.get_channel(ИД КАНАЛА)
await channel.send(news_content.text)
await channel.send("Оригинал новости: " + "https://stopgame.ru"+ url)
bot.run(config.settings['ТОКЕН'])