机器人未运行bs4 discord.py

时间:2019-01-24 00:57:10

标签: python beautifulsoup discord.py

所以我有一个机器人正在尝试运行,但是当我有此代码时

import discord
from discord.ext import commands
from bs4 import BeautifulSoup
import aiohttp

class daddy:
    """My custom cog that does stuff!"""

    def __init__(self, bot):
        self.bot = bot

@commands.command()
async def dottanow(self):
    """How many players are online atm?"""

    #Your code will go here
    url = "https://steamdb.info/app/570/graphs/" #build the web adress
    async with aiohttp.get(url) as response:
        soupObject = BeautifulSoup(await response.text(), "html.parser")
    try:
        online = soupObject.find(class_='home-stats').find('li').find('strong').get_text()
        await self.bot.say(online + ' players are playing this game at the moment')
    except:
        await self.bot.say("Couldn't load amount of players. No one is playing this game anymore or there's an error.")

def setup(bot):
    bot.add_cog(daddy(bot))

而且我不知道问题出在哪里,我的机器人没有执行任何操作,也无法打印到控制台,也没有将任何内容放入不和谐的地方,我确定我不会弄乱任何东西。但是,如果我愿意,请告诉我。我在Windows 10上使用py 3.6

1 个答案:

答案 0 :(得分:0)

该命令必须放在类内部。在您的代码中,它在类之外。

class daddy:
    """My custom cog that does stuff!"""

    def __init__(self, bot):
        self.bot = bot

    @commands.command()
    async def dottanow(self):
        ...