我有这个连接频道和帖子的代码,但是每当我运行这个代码时,它对1-2个频道执行这个操作,然后我得到一个错误:
回溯(最近一次调用):未定义asyncio.run( "C:/Users/Arnoldas/PycharmProjects/pythonProject/again.py",())中的文件主行97 NameError:名称'main‘。是什么导致了这个问题?我怎样才能让代码保持运行?
code:
from telethon.sync import TelegramClient
from telethon.tl.functions.channels import JoinChannelRequest
from telethon.errors.rpcerrorlist import FloodWaitError
import time
from dotenv import load_dotenv
import os
import asyncio
channel_list=['CocktailBar_Discussion',
'apmcoin_official',
'suprafinance',
'AuroraOfficialEN',
'HelloLambda',
'AlpacaCity',
'themorpheusnetwork',
'chiliz_io',
'BKEXEnglish',
'riodefiofficial',
'OnXFi',
'DeepOnionCoin',
'hellochromia',
'AnimeBEP20',
'daomaker',
'TheCoinEx',
'Ochain',
'pNetworkDefi',
'devprtcl',
'officialxyx',
'powerledger',
'bounce_finance',
'uncx_token',
'bounce_finance',
'concertVR1',
'obyteorg',
'telcoincommunity',
'DAAWallet',
'metahash_ENG',
'surf_finance',
'dfinity',
'xinfintalk',
'xcashglobal',
'propsproject',
'BTCPrivate',
'OIN_Finance_Eng',
'mithcash',
'hivenetwork',
'tokenown',
'trustverse_officialchannel',
'wax_io',
'TerraLunaChat',
'unit_en',
'FilecashGlobal',
'FryWorldFinance',
'originprotocol',
'LibraEcosystem',
'SpartanProtocolOrg',
'wgreenpay',
'cartesiproject',
'buymemecash',
'IGGalaxy',
'AlphaQuark',
'basedmoney',
'hybrixgroup',
'RYIUNITY',
'mftudotnet',
'MixDex',
'mithcash',
'mobius_network'
]
client = TelegramClient('session_name',
myid,
myapikey
)
client.start()
for values in channel_list:
try:
destination_channel_username=values
entity=client.get_entity(destination_channel_username)
client(JoinChannelRequest(channel=values))
client.send_message(entity=entity,message='Want to learn how we make crypto hedging easy? Join ProSwap Telegram channel ProSwapCommunity @ TG')
client.send_file(values, 'C:/Users/Arnoldas/Desktop/PROSWAP.png')
time.sleep(20)
except:
continue
time.sleep(20)
asyncio.run(main())发布于 2021-04-01 16:58:11
您尚未定义main函数。
像这样写你的代码:
from telethon.sync import TelegramClient
from telethon.tl.functions.channels import JoinChannelRequest
from telethon.errors.rpcerrorlist import FloodWaitError
import time
from dotenv import load_dotenv
import os
import asyncio
channel_list=['CocktailBar_Discussion',
'apmcoin_official',
'suprafinance',
'AuroraOfficialEN',
'HelloLambda',
'AlpacaCity',
'themorpheusnetwork',
'chiliz_io',
'BKEXEnglish',
'riodefiofficial',
'OnXFi',
'DeepOnionCoin',
'hellochromia',
'AnimeBEP20',
'daomaker',
'TheCoinEx',
'Ochain',
'pNetworkDefi',
'devprtcl',
'officialxyx',
'powerledger',
'bounce_finance',
'uncx_token',
'bounce_finance',
'concertVR1',
'obyteorg',
'telcoincommunity',
'DAAWallet',
'metahash_ENG',
'surf_finance',
'dfinity',
'xinfintalk',
'xcashglobal',
'propsproject',
'BTCPrivate',
'OIN_Finance_Eng',
'mithcash',
'hivenetwork',
'tokenown',
'trustverse_officialchannel',
'wax_io',
'TerraLunaChat',
'unit_en',
'FilecashGlobal',
'FryWorldFinance',
'originprotocol',
'LibraEcosystem',
'SpartanProtocolOrg',
'wgreenpay',
'cartesiproject',
'buymemecash',
'IGGalaxy',
'AlphaQuark',
'basedmoney',
'hybrixgroup',
'RYIUNITY',
'mftudotnet',
'MixDex',
'mithcash',
'mobius_network'
]
client = TelegramClient('session_name',
myid,
myapikey
)
client.start()
async def main():
for values in channel_list:
try:
destination_channel_username=values
entity=await client.get_entity(destination_channel_username)
await client(JoinChannelRequest(channel=values))
await client.send_message(entity=entity,message='Want to learn how we make crypto hedging easy? Join ProSwap Telegram channel ProSwapCommunity @ TG')
await client.send_file(values, 'C:/Users/Arnoldas/Desktop/PROSWAP.png')
await asyncio.sleep(20)
except:
continue
await asyncio.sleep(20)
asyncio.run(main())https://stackoverflow.com/questions/66901220
复制相似问题