Python Discord Bot-从另一个脚本返回变量

时间:2020-10-08 02:11:48

标签: python discord

我是Python的新手,如果这还不错,请原谅我,但这是我的代码,用于从网站上获取值并使用!scores不和谐地返回它。

scores()脚本用于获取值。我似乎无法在Discord中返回这些值。它说尚未定义Team1。谢谢!

import discord
from dotenv import load_dotenv
from discord.ext import commands
import pandas as pd
from bs4 import BeautifulSoup
import requests
import os

#Define Game URLs
game1='https://www.leaguegaming.com/forums/index.php?leaguegaming/league&action=league&page=game&gameid=607481&leagueid=73&seasonid=10&games=true'


load_dotenv()
TOKEN = hidden..

def scores():
    html=requests.get(game1).content
    df_list=pd.read_html(html)
    soup=BeautifulSoup(html)
    table=soup.select_one('table:contains("Team Stats")')
    df=pd.read_html(str(table))
    Team1Score=df[0].iloc[0,0]
    Team2Score=df[0].iloc[0,2]
    table=soup.select_one('table:contains("Half Stats")')
    df=pd.read_html(str(table))
    Team1=df[0].iloc[1,0]
    Team2=df[0].iloc[2,0]
    return(Team1,Team2)

description='''LG Scores Bot'''
bot=commands.Bot(command_prefix="!")

client = discord.Client()

@bot.event
async def on_ready():
    print(f'{client.user} has connected to Discord!')

@bot.command()
async def ping(ctx):
    await ctx.channel.send("pong")

@bot.command()
async def pin(ctx):
    await ctx.channel.send("pon")

@bot.command()
async def scores(ctx):
    scores()
    await ctx.channel.send(Team1)
    


bot.run(TOKEN)

0 个答案:

没有答案