0

This is the full code

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")

My problem is at

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}`")

I want to split the discord message that starts with !history for example "!history Leicester City/" put "Leicester City/" inside the variable team, and then run GameCheck on it. When I run this code it does not give me an error but it keeps giving me the same output no matter what "team" i put in.

1 Answers1

0

You are actually passing the entire message as the opposition team, the resulting url will be "https://www.11v11.com/teams/arsenal/tab/opposingTeams/opposition/!history%20Leicester%20City/" for the case you have shown. We simply have to remove the invoking command from the team name (remove !history)

team = " ".join(message.content.split()[1:]) #!history is the first word

Note: requests is a blocking library. I'd suggest using one of the answers there or using something like aiohttp.

Ceres
  • 2,498
  • 1
  • 10
  • 28