【发布时间】:2021-04-23 12:23:12
【问题描述】:
这是完整的代码
import discord
import os
import requests
from bs4 import BeautifulSoup
import lxml
client = discord.Client()
class GameCheck:
def __init__(self, name):
source = requests.get(f"https://www.11v11.com/teams/arsenal/tab/opposingTeams/opposition/{name}")
soup = BeautifulSoup(source.text, 'lxml')
games = soup.find_all(class_="result-status")
allgames = []
for game in games:
allgames.append(game.text)
self.last5 = allgames[-5:]
@client.event
async def on_ready():
print('We have logged in as {0.user}'.format(client))
@client.event
async def on_message(message):
if message.author == client.user:
return
if message.content.startswith('!history'):
team = message.content
ars = GameCheck(team)
await message.channel.send(f"`Our last 5 games with this club: {ars.last5}`")
client.run("Token")
我的问题在
if message.content.startswith('!history'):
team = message.content
ars = GameCheck(team)
await message.channel.send(f"`Our last 5 games with this club: {ars.last5}`")
我想拆分以 !history 开头的不和谐消息,例如 "!history Leicester City/" 将 "Leicester City/" 放入变量 team 中,然后对其运行 GameCheck。当我运行这段代码时,它不会给我一个错误,但无论我输入什么“团队”,它都会一直给我相同的输出。
【问题讨论】:
标签: python python-3.x python-requests discord.py