Вывести переменную парсера через бота Discord на Python

Пытаюсь вывести переменную items через команду бота, но она не определяется. Как решить?

import requests
from bs4 import BeautifulSoup
import discord
from discord.ext import commands
from discord.ext.commands import Bot


Bot = commands.Bot(command_prefix= '!')
client = discord.Client()

URL = 'site'
HEADERS = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36', 'accept': '*/*'}

def get_html(url, params=None):
    r = requests.get(url, headers=HEADERS, params=params)
    return r

def get_content(html):
    soup = BeautifulSoup(html, 'html.parser')
    items = soup.find_all('div', class_='player-name')

    print(items)



def parse():
    html = get_html(URL)
    if html.status_code == 200:
        get_content(html.text)


parse()

@Bot.command(pass_context = True)
async def code(ctx):
    html = get_html(URL)
    await ctx.send(html)

Bot.run('--------------')

Ответы (1 шт):

Автор решения: gil9red

Подправил код из вопроса и теперь items будет передано в ctx.send. Места, где изменил, выделил

Но есть вопрос: понимает ли ctx.send значение из items? А это результат выполнения soup.find_all, что, является списком элементов Tag из bs4. Возможно, нужно будет обработать items, чтобы, например, получить строку.

Код:

import requests
from bs4 import BeautifulSoup
import discord
from discord.ext import commands
from discord.ext.commands import Bot


Bot = commands.Bot(command_prefix= '!')
client = discord.Client()

URL = 'site'
HEADERS = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.198 Safari/537.36', 'accept': '*/*'}

def get_html(url, params=None):
    r = requests.get(url, headers=HEADERS, params=params)
    return r

def get_content(html):
    soup = BeautifulSoup(html, 'html.parser')
    items = soup.find_all('div', class_='player-name')
    return items
    # ^^^^^^^^^^^^^^^^^

def parse():
    r = get_html(URL)
    r.raise_for_status()
    return get_content(r.content)
    # ^^^^^^^^^^^^^^^^^


@Bot.command(pass_context = True)
async def code(ctx):
    items = parse()
    await ctx.send(items)
    # ^^^^^^^^^^^^^^^^^

Bot.run('--------------')
→ Ссылка