бот не работает bs4 discord.py - PullRequest
0 голосов
/ 24 января 2019

Итак, у меня есть бот, которого я пытаюсь запустить, но когда у меня есть этот код

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 голосов
/ 24 января 2019

Команда должна идти внутрь класса.В вашем коде это вне класса.

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

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

    @commands.command()
    async def dottanow(self):
        ...
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...