RuntimeWarning: coroutine was never awaited
12,008
Always for coroutines you need await. You forgot this in two places as you got async definitions.
So this code should now work (if this was the only problem):
import discord
from discord.ext import commands
import asyncio,aiohttp,json
from bs4 import BeautifulSoup as soup
class Pubg():
def __init__(self,bot):
self.bot = bot
async def get_info(self):
urlForInfo = await aiohttp.get("https://pubg.op.gg/user/"+user_info[0])
urlForInfo = await urlForInfo.text()
# urlForInfo = urllib.request.urlopen("https://pubg.op.gg/user/"+user[0]).read()
soup = bs.BeautifulSoup(urlForInfo, "lxml")
info = soup.find("div",{"class":"player-summary__name"})
playerID = info["data-user_id"]
playerNickname = info["data-user_nickname"]
season = soup.find("button",{"class":"ranked-stats-wrapper__season-btn"})
currentSeason = season["data-season"]
return playerID, playerNickname, currentSeason
async def get_kd(self):
playerID, playerNickname, currentSeason = await self.get_info()
url = "https://pubg.op.gg/api/users/{}/ranked-stats?season={}&server={}&queue_size={}&mode={}".format(playerID,currentSeason,user[3],user[1],user[2])
resp = requests.get(url).text
resp = json.loads(resp)
""" Player Game Stats """
kills = resp["stats"]["kills_sum"]
deaths = resp["stats"]["deaths_sum"]
killDeath = str(kills / deaths)
KD = killDeath[:4]
return KD
@commands.command(pass_context = True)
async def kd(self, ctx):
KD = await self.get_kd()
user_info = ctx.message.content.replace(".kd", "")
user = user_info.split("-")
await self.bot.say(f"Your K/D is: {KD}")
#await self.bot.say("test")
def setup(bot):
bot.add_cog(Pubg(bot))
Author by
Yeah
Updated on June 25, 2022Comments
-
Yeah 5 months
Been having a lot of trouble lately trying to make my Discord bot simply pull data from Pubg.op.gg and give the user its K/D.
I've been getting multiple errors, but the one that is showing up the most is:
F:\Python3\lib\site-packages\discord\ext\commands\core.py:50: RuntimeWarning: coroutine 'Pubg.get_kd' was never awaited ret = yield from coro(*args, **kwargs)From the error messaged I'm just confused on what excatly to await since I can't find Pubg.get_kd.
Heres my code:
import discord from discord.ext import commands import asyncio,aiohttp,json from bs4 import BeautifulSoup as soup class Pubg(): def __init__(self,bot): self.bot = bot async def get_info(self): urlForInfo = await aiohttp.get("https://pubg.op.gg/user/"+user_info[0]) urlForInfo = await urlForInfo.text() # urlForInfo = urllib.request.urlopen("https://pubg.op.gg/user/"+user[0]).read() soup = bs.BeautifulSoup(urlForInfo, "lxml") info = soup.find("div",{"class":"player-summary__name"}) playerID = info["data-user_id"] playerNickname = info["data-user_nickname"] season = soup.find("button",{"class":"ranked-stats-wrapper__season-btn"}) currentSeason = season["data-season"] return playerID, playerNickname, currentSeason async def get_kd(self): playerID, playerNickname, currentSeason = self.get_info() url = "https://pubg.op.gg/api/users/{}/ranked-stats?season={}&server={}&queue_size={}&mode={}".format(playerID,currentSeason,user[3],user[1],user[2]) resp = requests.get(url).text resp = json.loads(resp) """ Player Game Stats """ kills = resp["stats"]["kills_sum"] deaths = resp["stats"]["deaths_sum"] killDeath = str(kills / deaths) KD = killDeath[:4] return KD @commands.command(pass_context = True) async def kd(self, ctx): KD = self.get_kd() user_info = ctx.message.content.replace(".kd", "") user = user_info.split("-") await self.bot.say(f"Your K/D is: {KD}") #await self.bot.say("test") def setup(bot): bot.add_cog(Pubg(bot))