Python Discord Bot-从另一个脚本返回变量
我对Python非常陌生,所以如果这不合适,请原谅我,但是。。下面是我的代码,可以从网站中获取值,并使用!得分 scores()脚本用于获取值。我似乎无法在不一致的情况下返回这些值。它说Team1没有定义。谢谢Python Discord Bot-从另一个脚本返回变量,python,discord,Python,Discord,我对Python非常陌生,所以如果这不合适,请原谅我,但是。。下面是我的代码,可以从网站中获取值,并使用!得分 scores()脚本用于获取值。我似乎无法在不一致的情况下返回这些值。它说Team1没有定义。谢谢 import discord from dotenv import load_dotenv from discord.ext import commands import pandas as pd from bs4 import BeautifulSoup import requests
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)
您需要将返回的值分配给变量<代码>团队1,团队2=分数()