0

帮助:相对较新的电视节目并且遇到delete_messages()功能问题。它“似乎”对我无济于事......

最初,我从返回对象的 id 值中从 send_message 获取消息 id。它返回 1、2 等值。但不确定这是消息 ID。

我把它发送delete_messagesdelete_messages(channel, [id])

我从以下渠道获得频道(这是一个私人频道):

def resolve_channel_id(self, name):
    try:
        if name in self.__channel_ids:
            return self.__channel_ids[name]

        channel_id = self.client(ResolveUsernameRequest(name))
        self.__channel_ids[name] = channel_id
        return channel_id

    # except UserNameNotOccupiedError as err:
    except Exception as err:
        # try for private channel
        chatinvite = self.client(CheckChatInviteRequest(name))
        channel_id = chatinvite.chat.id
        access_hash_channel = chatinvite.chat.access_hash
        channel_id = InputChannel(channel_id, access_hash_channel)
        self.__channel_ids[name] = channel_id
        return channel_id
4

2 回答 2

1

希望这个例子对朋友有用:‌</p>

通过此代码,如果将带有Hello文本的消息发送到 ID 的组-1001300989487,则该文本将被删除。

import logging


from telethon import TelegramClient, events

logging.basicConfig(level=logging.INFO)

api_id = XXXXXX
api_hash = 'XXXXXXXXXXXXXXXXXXXXXXX'
phone_number = '+989XXXXXXXX'

################################################

client = TelegramClient('session_name',
                    api_id,
                    api_hash, 
                    )


@client.on(events.NewMessage(chats=(-1001300989487)))
async def my_event_handler(event):
    if 'hello' in event.raw_text:
        await event.delete()


client.start()
client.run_until_disconnected()

print('finish')
于 2018-08-22T20:55:02.503 回答
0

通过更新到最新的 Telethon 工作:1.0.3,并遵循文档... https://telethon.readthedocs.io/en/latest/extra/basic/asyncio-magic.html

于 2018-07-09T00:41:07.043 回答