2017-12-23 43 views
1

글쎄, 파이썬 3을 사용하는 Discord 봇에서 일하고 있는데 어느 정도는 작동하지만 몇 분마다 충돌을 계속합니다. 그것은 나에게 "작업이 중지되었지만 보류 중"과 같은 오류를줍니다. 이제, 문제를 조사하고 내 응답 = request.get (url)을 제거하고 "async with aiohttp.get (url) in response"로 대체해야하는 정보를 발견했습니다. 이제 내가 이런 식으로 할 때, 그것은 "coroutine '가용성이 결코"기다리지 않았다 "라고 나에게 준다. 이 문제를 해결하려면 루프의 일종을 사용해야한다고 생각하지만, 나는 비동기적인 것들에 대해 상당히 새로운 것이므로 아무런 단서가 없다.파이썬 불화 봇 - 코 루틴은 절대로 기다려지지 않았습니다.

import discord 
from discord.ext.commands import Bot 
from discord.ext import commands 
import asyncio 
import time 

import requests 
from bs4 import BeautifulSoup 
import smtplib 
import aiohttp 
import async_timeout 


async def availability(): 
    url = "some url" 
    headers = {'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'} 
    async with aiohttp.ClientSession().get(url, headers=headers) as response: 
     soup = BeautifulSoup(response.text, "lxml") 
     print(soup) 
     return soup 


Client = discord.Client() 
bot_prefix= "?" 
client = commands.Bot(command_prefix=bot_prefix) 


availible = True 


@client.event 
async def on_ready(): 
    print("Bot Online!") 
    print("Name: {}".format(client.user.name)) 
    print("ID: {}".format(client.user.id)) 

    bessie = 0 
    waittime = 0 

    while True: 
     time.sleep(1) 
     if wachttijd == 0: 
      if ("0 available") not in str(availability()): 
       bessie = bessie + 1 
       if bessie == 3: 
        await client.send_message(discord.Object(id='some id'), 
               '<@&some channel>some text!') 
        print("available") 
        bessie = 0 
        waittime = 10 
      else: 
       bessie = 0 
     else: 
      wachttijd = wachttijd - 1 



client.run("token") 

누군가가 도와 줄 수 있습니까?

+2

'await availability()'를 사용해야합니다. – dirn

답변

0

그러나 나는 약간의 연구와 코드에 따라 내가 this stackoverflow thread에서 보았을 때 response.text를 기다리고 있지 않기 때문에 이것이 100 % 확실하지는 않습니다. response.text의 앞에 await를 키워드를 추가

시도 : discord.py를 사용하는 경우

soup = BeautifulSoup(await response.text(), "lxml") 

또한 이 (time.sleep를 사용하지 않는) 대신 'await asyncio.sleep(seconds)

당신에게 사용 가능하다면 블로킹을 피하기 때문에 봇이 정지 될 수 있습니다. 자세한 내용은 "FAQ" section of the discord.py docs에서 확인할 수 있습니다.