如何解决热解图回调函数
根据 Pyrogram 库文档,我正在尝试使用可调用函数设置“phone_code”参数,但我总是收到此错误,有人可以帮助我吗?
if (msg.startsWith(prefix + "prune") || msg.startsWith(prefix + "purge") || msg.startsWith(prefix + "delete")) {
...
var embedERRPRUNE5 = new discord.MessageEmbed()
.setColor("#8c00ee")
.setTitle("❌Something went wrong,while deleting messages.")
.setAuthor("Vittorio De STradis ツ","https://cdn.discordapp.com/attachments/784128595084705853/790590227277545502/Cowboy_Bepop_1.png","...")
.setFooter("If you need help,pls contact me!","https://cdn.discordapp.com/attachments/784128595084705853/790590227277545502/Cowboy_Bepop_1.png")
.setTimestamp();
var embedPRUNE = new discord.MessageEmbed()
.setColor("#8c00ee")
.setTitle(`✔ Deleted ${message.size}/${args[0]} messages.`)
.setAuthor("Vittorio De STradis ツ","https://cdn.discordapp.com/attachments/784128595084705853/790590227277545502/Cowboy_Bepop_1.png")
.setTimestamp();
await message.delete()
await message.channel.bulkDelete(args[0])
.then(message => message.channel.send(embedPRUNE)).then(d => d.delete({timeout: 15000})) // In quanto tempo questo messaggio verrà eliminato (in ms).
.catch(() => message.channel.send(embedERRPRUNE5)) // Questo errore comparirà quando il bot non ha l'accesso per farlo.
}```
错误:
from pyrogram import Client
import time
def codePhone(phone_number):
print('numero')
sleep (10)
return '2154'
app = Client("my_account",phone_number='39**********',phone_code=codePhone)
with app:
app.send_message("me","Hi!")
解决方法
对不起,我不认为我完全理解这里的要求,但从它的外观来看,您需要让它工作。因此,在这种情况下,您需要了解将什么作为参数传递给函数。
由于 codePhone
函数接受一个参数 (phone_number),但在您的 Client 类中,您只是将其作为回调引用发送,这似乎是不正确的。
此外,根据模块 (Pyrogram) here 的文档,phone_code
参数需要是字符串(很可能是数字字符串 -> '2154')。因此,请尝试使用它。
告诉我这是否适合您。
TL;DR:使用
app = Client("my_account",phone_number='39**********',phone_code='2154')
,
您使用的是 1.0.7 版,但support for callback functions for parameters for Client was removed in ver. 0.16.0
删除了对客户端参数的回调函数的支持,例如 phone_number,phone_code,password,... 支持更简单和 顺序授权流程。
目前它希望您为 str
提供 phone_code
。
phone_number
类中的 Client
参数采用字符串,而不是函数。如果您想自动化电话号码登录的过程:
from pyrogram import Client
from pyrogram.errors import SessionPasswordNeeded
import os
api_id = input('API ID: ')
api_hash = input('API HASH: ')
phone = input('Phone Number (with +): ')
def connect():
try:
client = Client(phone,api_id,api_hash)
client.connect()
code = client.send_code(phone)
try:
signed_in = client.sign_in(phone,code.phone_code_hash,input('Verification Code: '))
client.accept_terms_of_service(signed_in.id)
except SessionPasswordNeeded:
client.check_password(input('Two-Step Verification password: '))
client.disconnect()
except Exception as ex:
os.remove(f'{phone}.session')
print(f'Error !\n\t`{type(ex).__name__}`\n\t{ex}')
return
with client as app:
app.send_message('me',"Hey it's YOU!")
if __name__ == '__main__':
connect()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。