我是 Python 新手,为了了解这种语言,我决定创建 Telegram BOT。我在尝试与 supabase 连接时遇到问题,如果问题出在语法上,或者我是否忘记了某些东西,则为 idk。
我需要使用带有此代码的RPC(存储过程)获取一个随机文档,但我收到一个错误:
/Users/alvarogoederivera/web/python_bot/lib/python3.8/site-packages/telegram/ext/dispatcher.py:555: RuntimeWarning: coroutine 'random_quote' was never awaited
handler.handle_update(update, self, check, context)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback
import logging
import asyncio
import os
import telegram
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters
from supabase_py import create_client, Client
from dotenv import load_dotenv
load_dotenv()
url: str = os.getenv("SUPABASE_URL")
key: str = os.getenv("SUPABASE_KEY")
token: str = os.getenv("TELEGRAM_TOKEN")
supabase: Client = create_client(url, key)
#Conf Logging
logging.basicConfig(
level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
)
logger = logging.getLogger()
def start(update):
logger.info(f"El usuario {update.effective_user['username']}, ha iniciado")
name = update.effective_user['first_name']
update.message.reply_text(f"Hola {name} yo soy tu bot")
async def random_quote(update, context):
quote = await supabase.rpc('get_random_quote', {})
print(quote)
# user_id = update.effective_user['id']
# logger.info(f"el usuario {user_id} ha solicitado una frase")
# context.bot.sendMessage(chat_id = user_id, parse_mode="MarkdownV2", text=f"_Frase_ *x*")
def echo(update, context):
user_id = update.effective_user['id']
logger.info(f"el usuario {user_id} ha enviado un mensaje")
text = update.message.text
context.bot.sendMessage(chat_id = user_id, parse_mode="MarkdownV2", text=f"_escribiste_ *{text}*")
if __name__ == "__main__":
bot = telegram.Bot(token = token)
updater = Updater(bot.token)
dp = updater.dispatcher
loop = asyncio.get_event_loop()
loop.run_until_complete(random_quote({}, {}))
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("random", random_quote))
dp.add_handler(MessageHandler(Filters.text, echo))
updater.start_polling()
print("BOT LOAD")
updater.idle()
有谁知道如何获取数据?