首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >错误: ModuleNotFoundError:没有名为“Telethon”的模块

错误: ModuleNotFoundError:没有名为“Telethon”的模块
EN

Stack Overflow用户
提问于 2021-12-08 13:43:26
回答 2查看 1.3K关注 0票数 -1

我试图使用Python创建一个Telegram Bot,并得到以下错误:

代码语言:javascript
复制
ModuleNotFoundError: No module named 'Telethon'

我已经试过了

代码语言:javascript
复制
pip3 install telethon

还有这个

代码语言:javascript
复制
pip install telethon

就像这里:ModuleNotFoundError:没有名为“telethon”的模块

但是错误仍然是一样的。当我安装telethon时,除了运行以下代码外,没有错误:

代码语言:javascript
复制
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上也是同样的错误。

我能做什么?

EN

回答 2

Stack Overflow用户

发布于 2021-12-08 13:47:40

您应该删除import TelegramClient,然后执行import telethon操作。

票数 1
EN

Stack Overflow用户

发布于 2021-12-08 13:49:24

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

代码语言:javascript
复制
git clone https://github.com/LonamiWebs/Telethon
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70276018

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档