#Trying to use interactions with flask server

1 messages · Page 1 of 1 (latest)

coarse quest
#

Hello!
I'm trying to build a webserver which allows me to check if certain users have a certain role in a server using flask, and i'm getting a weird error when making interactions.get() calls.

Here's my code:

from flask import Flask, request
import interactions
import threading
from os import environ
import asyncio

app = Flask("app")
client = interactions.Client("TOKEN")

@app.route("/<user>")
async def index(user):
    member: interactions.Member = await interactions.get(
        client, 
        interactions.Member, 
        object_id=int(user), 
        parent_id=int(request.args.get("guild_id")),
        force=True
    )
    return int(request.args.get("role")) in member.roles

app.run(host="0.0.0.0", port=443)
threading.Thread(target=client.start).start()

Here's my error:

[2024-01-07 10:49:42,379] ERROR in app: Exception on /1193568458533777478 [GET]
Traceback (most recent call last):
  File "/opt/homebrew/lib/python3.11/site-packages/flask/app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/flask/app.py", line 1486, in full_dispatch_request
    rv = self.handle_user_exception(e)
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/flask/app.py", line 1484, in full_dispatch_request
    rv = self.dispatch_request()
         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/flask/app.py", line 1469, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/asgiref/sync.py", line 277, in __call__
    return call_result.result()
           ^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py", line 449, in result
    return self.__get_result()
           ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.11.6_1/Frameworks/Python.framework/Versions/3.11/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
    raise self._exception
  File "/opt/homebrew/lib/python3.11/site-packages/asgiref/sync.py", line 353, in main_wrap
    result = await self.awaitable(*args, **kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/metatron/Documents/coding/course4-uaw/bot/main.py", line 12, in index
    member: interactions.Member = await interactions.get(
                                        ^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/interactions/utils/get.py", line 230, in get
    _get_cache(obj, client, kwarg_name, **kwargs) if not force_http else None
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.11/site-packages/interactions/utils/get.py", line 312, in _get_cache
    _obj = client._http.cache[_object].get(_values)
           ^^^^^^^^^^^^^^^^^^
AttributeError: 'str' object has no attribute 'cache'
spring saddleBOT
#

Hey! Once your issue is solved, press the button below to close this thread!

spring saddleBOT
solid knoll
#

Ive tried something like this as well but it doesnt seem to work well having 2 giant frameworks in the same process

#

Ive been getting asyncio errors all over the place

#

Even splitting them into threads, asyncio doesnt like it

#

So youd probably have a socket running for inter process communication and somehow send your stuff back and forth

sullen elk