0
I’m creating a bot in the Discord that displays the films available in the cinema. It turns out I already had a Web Crawler in Python that did this, and I decided to put it to work on the bot by executing a command. However, when running it by the bot it only returned the first value of the list of movies, so I put the Return out of the for thinking it would solve, but now it returns only the second movie, instead of returning all (I would like to display all the available movies by the bot). How do I return all values of "t1" ?
# bot.py
import os
import random
import discord
from dotenv import load_dotenv
import bs4
from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as soup
import pandas as pd
load_dotenv()
TOKEN = os.getenv('token')
GUILD = os.getenv('Teste BOT')
client = discord.Client()
@client.event
async def on_ready():
for guild in client.guilds:
if guild.name == GUILD:
break
print(
f'{client.user} is connected to the following guild:\n'
f'{guild.name}(id: {guild.id})\n'
)
members = '\n - '.join([member.name for member in guild.members])
print(f'Guild Members:\n - {members}')
@client.event
async def on_message(message):
if message.author == client.user:
return
def filmes():
my_url = 'https://iguatemi.com.br/saocarlos/cinema/'
uClient = uReq(my_url)
page_html = uClient.read()
uClient.close()
page_soup = soup(page_html, "html.parser")
for title in page_soup.select('li.node-readmore > a'):
t1 = title.get('title')
return t1
if message.content == 'filmes!':
response = filmes()
await message.channel.send(response)
client.run('Token')
t1 = title.get('title')
- you are "overwriting" the value oft1
in the loop. If the idea is to return a list of items, you should do theappend
with all values obtained intitle.get('title')
.– Renan Gomes
I posted a solution, however I was still editing some typos, but now this right, a check now and if you have any doubts just say, and the use of embed is very cool, you will enjoy
– Guilherme França de Oliveira