1

I'm making a rule34 bot for discord witch uses asynco I'm using the getImages() function with should work with if r34 equals rule34.Rule34(my current loop)

my code

import discord
import rule34
import nest_asyncio

nest_asyncio.apply()
client = discord.Client()

class bot:
    def __init__(self, message):
        client = discord.Client()
        self.r34 = rule34.Rule34(client.loop)
        self.message = message

    async def send(self, message): #retrives and sends the image
        post = await self.r34.getImages(singlePage=True, OverridePID=1, tags=message.content.split()[1:]) #retrives rule34 object
        print(post)


@client.event
async def on_message(message):
    if message.content.startswith("?p"): #if it's requesting rule34
        post = bot(message)
        await post.send(message)

client.run('MY TOKEN')

the output

Ignoring exception in on_message
Traceback (most recent call last):
  File "/home/lj_fin/.local/lib/python3.6/site-packages/discord/client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "schmeckle.py", line 29, in on_message
    await post.send(message)
  File "schmeckle.py", line 17, in send
    post = await self.r34.getImages(singlePage=True, OverridePID=1, tags=message.content.split()[1:]) #retrives rule34 object
  File "/home/lj_fin/.local/lib/python3.6/site-packages/rule34/rule34.py", line 161, in getImages
    num = await self.totalImages(tags)
  File "/home/lj_fin/.local/lib/python3.6/site-packages/rule34/rule34.py", line 131, in totalImages
    with async_timeout.timeout(10):
  File "/home/lj_fin/.local/lib/python3.6/site-packages/async_timeout/__init__.py", line 39, in __enter__
    return self._do_enter()
  File "/home/lj_fin/.local/lib/python3.6/site-packages/async_timeout/__init__.py", line 76, in _do_enter
    raise RuntimeError('Timeout context manager should be used '
RuntimeError: Timeout context manager should be used inside a task

the output when I cancel the program

Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/home/lj_fin/.local/lib/python3.6/site-packages/rule34/rule34.py", line 53, in _exitHandler
    asyncio.run_coroutine_threadsafe(self.session.close(), loop=self.loop)
  File "/usr/lib/python3.6/asyncio/tasks.py", line 725, in run_coroutine_threadsafe
    loop.call_soon_threadsafe(callback)
  File "/usr/lib/python3.6/asyncio/base_events.py", line 637, in call_soon_threadsafe
    self._check_closed()
  File "/usr/lib/python3.6/asyncio/base_events.py", line 377, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/home/lj_fin/.local/lib/python3.6/site-packages/rule34/rule34.py", line 53, in _exitHandler
    asyncio.run_coroutine_threadsafe(self.session.close(), loop=self.loop)
  File "/usr/lib/python3.6/asyncio/tasks.py", line 725, in run_coroutine_threadsafe
    loop.call_soon_threadsafe(callback)
  File "/usr/lib/python3.6/asyncio/base_events.py", line 637, in call_soon_threadsafe
    self._check_closed()
  File "/usr/lib/python3.6/asyncio/base_events.py", line 377, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7effb8ac87b8>
sys:1: RuntimeWarning: coroutine 'ClientSession.close' was never awaited
Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7effb38f5518>
lucas
  • 21
  • 3

1 Answers1

0

shouldn't client be commands.Bot instead of discord.Client

Edit: I know this isn't an 'answer' but I don't have enough rep for adding a comment.