[英]Calling a function in pyrogram from another Python file
In Pyrogram package, how can I call a function from another Python script?在 Pyrogram package 中,如何从另一个 Python 脚本调用 function?
For example, suppose that the Pyrogram function takes two arguments chat_id
and text
as input and then send text
to given chat_id
.例如,假设 Pyrogram function 将两个 arguments
chat_id
和text
作为输入,然后将text
发送到给定chat_id
。
We know that app.send_message(chat_id = given_chat_id,text = given_text)
method is send given_text
to given_chat_id
,我们知道
app.send_message(chat_id = given_chat_id,text = given_text)
方法是将given_text
发送到given_chat_id
,
Suppose there are two files named run.py
and tel.py
in the same folder.假设在同一个文件夹中有两个名为
run.py
和tel.py
的文件。
File run.py
should contain this script:文件
run.py
应该包含这个脚本:
from tel import my_func
my_func(given_chat_id, given_text)
and tel.py
should look like this code:和
tel.py
应该看起来像这样的代码:
from pyrogram import Client
app = Client("my_account")
async def my_func(chat_id, text):
print("Hello world!")
await app.send_message(chat_id, text)
app.run()
We know it doesn't work.我们知道这行不通。 when I run
run.py
file Even the phrase Hello world!
当我运行
run.py
文件时,即使是短语Hello world!
is not printed.不打印。
I don't know how to call it.我不知道怎么称呼它。
You should Use decorator before your function您应该在 function 之前使用装饰器
from pyrogram import Client
app = Client("my_account")
@app.on_message()
def log(client, message):
print(message)
app.run()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.