【问题标题】:ERROR: ModuleNotFoundError: No module named 'Telethon'错误:ModuleNotFoundError:没有名为“Teleton”的模块
【发布时间】:2022-01-13 11:08:20
【问题描述】:

我正在尝试使用 Python 创建 Telegram Bot,但出现以下错误:

ModuleNotFoundError: No module named 'Telethon'

我已经试过了:

pip3 install telethon

还有这个

pip install telethon

喜欢这里:ModuleNotFoundError: No module named 'telethon'

但错误仍然相同。当我安装 Telethon 时没有错误但运行此代码:

import Telethon
import TelegramClient

from telethon.sync import TelegramClient
from telethon.tl.functions.messages import GetDialogsRequest
from telethon.tl.types import InputPeerEmpty
import csv
 
api_id = placeholder-myid
api_hash = 'placeholder-myhash'
phone = '+ placeholder-myNumber'
client = TelegramClient(phone, api_id, api_hash)
 
client.connect()
if not client.is_user_authorized():
    client.send_code_request(phone)
    client.sign_in(phone, input('Enter the code: '))
 
chats = []
last_date = None
chunk_size = 200
groups=[]
 
result = client(GetDialogsRequest(
             offset_date=last_date,
             offset_id=0,
             offset_peer=InputPeerEmpty(),
             limit=chunk_size,
             hash = 0
         ))
chats.extend(result.chats)
 
for chat in chats:
    try:
        if chat.megagroup== True:
            groups.append(chat)
    except:
        continue
 
print('Choose a group to scrape members from:')
i=0
for g in groups:
    print(str(i) + '- ' + g.title)
    i+=1
 
g_index = input("Enter a Number: ")
target_group=groups[int(g_index)]
 
print('Fetching Members...')
all_participants = []
all_participants = client.get_participants(target_group, aggressive=True)
 
print('Saving In file...')
with open("members.csv","w",encoding='UTF-8') as f:
    writer = csv.writer(f,delimiter=",",lineterminator="\n")
    writer.writerow(['username','user id', 'access hash','name','group', 'group id'])
    for user in all_participants:
        if user.username:
            username= user.username
        else:
            username= ""
        if user.first_name:
            first_name= user.first_name
        else:
            first_name= ""
        if user.last_name:
            last_name= user.last_name
        else:
            last_name= ""
        name= (first_name + ' ' + last_name).strip()
        writer.writerow([username,user.id,user.access_hash,name,target_group.title, target_group.id])      
print('Members scraped successfully.')

我知道在 https://replit.com 上试试这个,因为我想我在 Mac 上下载任何东西时可能犯了一个错误,但在 replit.com 上也是同样的错误。

我能做什么?

【问题讨论】:

  • 这与问题无关,但请注意,尝试抓取成员并大量添加它们被视为垃圾邮件,并且可能会删除帐户和频道。

标签: python telegram-bot telethon


【解决方案1】:

您应该删除import TelegramClient 并改为使用import telethon

【讨论】:

  • 应该是小写的相关点吗?因为他们已经在做import Telethon(在import TelegramClient之上)。
  • 是的,python 区分大小写
【解决方案2】:

我解决了。 我不得不这样做:

git clone https://github.com/LonamiWebs/Telethon

【讨论】:

    猜你喜欢
    • 2020-07-30
    • 2020-01-01
    • 2019-03-09
    • 2019-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多