python - bot 没有运行 bs4 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
解决方案
该命令必须进入类内部。在您的代码中,它在类之外。
class daddy:
"""My custom cog that does stuff!"""
def __init__(self, bot):
self.bot = bot
@commands.command()
async def dottanow(self):
...
推荐阅读
- java - 为什么这在纸上有效,但逻辑在代码上无效
- mips - MIPS 关于在添加两个整数时使用 ($zero) 的问题
- php - 如何以编程方式计算直线和平面之间的交点?
- python - 不使用 sort() 按字母顺序对单词列表进行排序
- javascript - Jquery如何将类附加到生成的数组数字?
- tensorflow - 使用 tensorflow + opencv 引发 e.ag_error_metadata.to_exception(e)
- javascript - React 路由器更改 url 但不更改组件 [已解决]
- mongoose - MongoDB Atlas 按引用的文档字段搜索词搜索
- php - Laravel 7 - 由于登录尝试失败而重定向回来后如何在登录表单中显示旧输入?
- javascript - 购物车增量和减量值 JS