337 lines
18 KiB
HTML
337 lines
18 KiB
HTML
|
||
|
||
<!DOCTYPE html>
|
||
<!--[if IE 8]><html class="no-js lt-ie9" lang="zh-CN" > <![endif]-->
|
||
<!--[if gt IE 8]><!--> <html class="no-js" lang="zh-CN" > <!--<![endif]-->
|
||
<head>
|
||
<meta charset="utf-8">
|
||
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
|
||
<title>iter_messages() — Xtaothon Documentation</title>
|
||
|
||
|
||
|
||
|
||
<link rel="shortcut icon" href="../../_static/favicon.ico"/>
|
||
|
||
|
||
|
||
<link rel="canonical" href="https://docs.xtaolabs.com/api/methods/iter_messages.html"/>
|
||
|
||
|
||
|
||
<script type="text/javascript" src="../../_static/js/modernizr.min.js"></script>
|
||
|
||
|
||
<script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script>
|
||
<script src="../../_static/jquery.js"></script>
|
||
<script src="../../_static/underscore.js"></script>
|
||
<script src="../../_static/doctools.js"></script>
|
||
<script src="../../_static/clipboard.min.js"></script>
|
||
<script src="../../_static/copybutton.js"></script>
|
||
<script src="../../_static/translations.js"></script>
|
||
|
||
<script type="text/javascript" src="../../_static/js/theme.js"></script>
|
||
|
||
|
||
|
||
|
||
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
|
||
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
|
||
<link rel="stylesheet" href="../../_static/copybutton.css" type="text/css" />
|
||
<link rel="stylesheet" href="../../_static/tabs.css" type="text/css" />
|
||
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
|
||
<link rel="index" title="索引" href="../../genindex.html" />
|
||
<link rel="search" title="搜索" href="../../search.html" />
|
||
<link rel="next" title="get_messages()" href="get_messages.html" />
|
||
<link rel="prev" title="forward_messages()" href="forward_messages.html" />
|
||
</head>
|
||
|
||
<body class="wy-body-for-nav">
|
||
|
||
|
||
<div class="wy-grid-for-nav">
|
||
|
||
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
|
||
<div class="wy-side-scroll">
|
||
<div class="wy-side-nav-search" >
|
||
|
||
|
||
|
||
<a href="../../index.html">
|
||
|
||
|
||
|
||
|
||
<img src="../../_static/xtaothon.png" class="logo" alt="Logo"/>
|
||
|
||
</a>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<div role="search">
|
||
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
|
||
<input type="text" name="q" placeholder="Search docs" />
|
||
<input type="hidden" name="check_keywords" value="yes" />
|
||
<input type="hidden" name="area" value="default" />
|
||
</form>
|
||
</div>
|
||
|
||
|
||
</div>
|
||
|
||
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<p class="caption"><span class="caption-text">简介</span></p>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../intro/quickstart.html">快速开始</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../intro/install.html">安装指南</a></li>
|
||
</ul>
|
||
<p class="caption"><span class="caption-text">开始</span></p>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../start/auth.html">授权</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../start/invoking.html">调用方法</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../start/updates.html">处理消息</a></li>
|
||
</ul>
|
||
<p class="caption"><span class="caption-text">API</span></p>
|
||
<ul class="current">
|
||
<li class="toctree-l1"><a class="reference internal" href="../client.html">客户端</a></li>
|
||
<li class="toctree-l1 current"><a class="reference internal" href="index.html">可用方法</a><ul class="current">
|
||
<li class="toctree-l2"><a class="reference internal" href="index.html#id3">基础</a></li>
|
||
<li class="toctree-l2 current"><a class="reference internal" href="index.html#id4">消息</a><ul class="current">
|
||
<li class="toctree-l3"><a class="reference internal" href="send_message.html">send_message</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="edit_message.html">edit_message</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="delete_messages.html">delete_messages</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="forward_messages.html">forward_messages</a></li>
|
||
<li class="toctree-l3 current"><a class="current reference internal" href="#">iter_messages</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="get_messages.html">get_messages</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="pin_message.html">pin_message</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="unpin_message.html">unpin_message</a></li>
|
||
<li class="toctree-l3"><a class="reference internal" href="send_read_acknowledge.html">send_read_acknowledge</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l2"><a class="reference internal" href="index.html#id5">上传</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="index.html#id6">下载</a></li>
|
||
<li class="toctree-l2"><a class="reference internal" href="index.html#id7">用户</a></li>
|
||
</ul>
|
||
</li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../types/index.html">可用类型</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../bound-methods/index.html">绑定方法</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../handlers.html">消息更新处理器</a></li>
|
||
</ul>
|
||
<p class="caption"><span class="caption-text">主题指南</span></p>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../topics/proxy.html">SOCKS5 Proxy</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../topics/text-formatting.html">文本格式</a></li>
|
||
</ul>
|
||
<p class="caption"><span class="caption-text">更多</span></p>
|
||
<ul>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../faq.html">FAQ</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../glossary.html">常见短语</a></li>
|
||
<li class="toctree-l1"><a class="reference internal" href="../../support.html">支持 Xtaothon</a></li>
|
||
</ul>
|
||
|
||
|
||
|
||
</div>
|
||
</div>
|
||
</nav>
|
||
|
||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
|
||
|
||
|
||
<nav class="wy-nav-top" aria-label="top navigation">
|
||
|
||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
||
<a href="../../index.html">xtaothon</a>
|
||
|
||
</nav>
|
||
|
||
|
||
<div class="wy-nav-content">
|
||
|
||
<div class="rst-content style-external-links">
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<div role="navigation" aria-label="breadcrumbs navigation">
|
||
|
||
<ul class="wy-breadcrumbs">
|
||
|
||
<li><a href="../../index.html">Docs</a> »</li>
|
||
|
||
<li><a href="index.html">可用方法</a> »</li>
|
||
|
||
<li>iter_messages()</li>
|
||
|
||
|
||
<li class="wy-breadcrumbs-aside">
|
||
|
||
|
||
|
||
<!-- User defined GitHub URL -->
|
||
<a href="https://github.com/Xtao-Labs/docs-all" class="fa fa-github"> Edit on GitHub</a>
|
||
|
||
|
||
|
||
</li>
|
||
|
||
</ul>
|
||
|
||
|
||
<hr/>
|
||
</div>
|
||
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
||
<div itemprop="articleBody">
|
||
|
||
<div class="section" id="iter-messages">
|
||
<h1>iter_messages()<a class="headerlink" href="#iter-messages" title="永久链接至标题">¶</a></h1>
|
||
<dl class="py method">
|
||
<dt id="telethon.Client.iter_messages">
|
||
<code class="sig-prename descclassname"><span class="pre">Client.</span></code><code class="sig-name descname"><span class="pre">iter_messages</span></code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#telethon.Client.iter_messages" title="永久链接至目标">¶</a></dt>
|
||
<dd><p>搜索指定对话中的消息。</p>
|
||
<dl>
|
||
<dt>参数:</dt><dd><dl>
|
||
<dt>entity (<a class="reference internal" href="../types/user.html#telethon.tl.types.user" title="telethon.tl.types.user"><code class="xref py py-obj docutils literal notranslate"><span class="pre">user</span></code></a> | <a class="reference internal" href="../types/chat.html#telethon.tl.types.chat" title="telethon.tl.types.chat"><code class="xref py py-obj docutils literal notranslate"><span class="pre">chat</span></code></a> | <a class="reference internal" href="../types/channel.html#telethon.tl.types.channel" title="telethon.tl.types.channel"><code class="xref py py-obj docutils literal notranslate"><span class="pre">channel</span></code></a>):</dt><dd><p>需要检索的对话的对象</p>
|
||
</dd>
|
||
<dt>limit (<code class="docutils literal notranslate"><span class="pre">int</span></code> | <code class="docutils literal notranslate"><span class="pre">None</span></code>, <em>可选</em>):</dt><dd><p>限制要检索的消息数。由于API的限制,检索超过 <code class="docutils literal notranslate"><span class="pre">3000</span></code> 条消息将需要超过半分钟。</p>
|
||
<p>配置为 <code class="docutils literal notranslate"><span class="pre">None</span></code> ,并不会返回所有历史。</p>
|
||
</dd>
|
||
<dt>offset_date (<code class="docutils literal notranslate"><span class="pre">float</span></code>, <em>可选</em>):</dt><dd><p>将从此时间之前开始检索消息。</p>
|
||
</dd>
|
||
<dt>offset_id (<code class="docutils literal notranslate"><span class="pre">int</span></code>, <em>可选</em>):</dt><dd><p>将从此消息 id 之前开始检索消息。</p>
|
||
</dd>
|
||
<dt>max_id (<code class="docutils literal notranslate"><span class="pre">int</span></code>, <em>可选</em>):</dt><dd><p>配置要检索到的消息的最大 id 值。</p>
|
||
</dd>
|
||
<dt>min_id (<code class="docutils literal notranslate"><span class="pre">int</span></code>, <em>可选</em>):</dt><dd><p>配置要检索到的消息的最小 id 值。</p>
|
||
</dd>
|
||
<dt>search (<code class="docutils literal notranslate"><span class="pre">str</span></code>, <em>可选</em>):</dt><dd><p>配置检索的字符串。</p>
|
||
</dd>
|
||
<dt>filter (<code class="docutils literal notranslate"><span class="pre">MessagesFilter</span></code>, <em>可选</em>):</dt><dd><p>过滤消息类型。</p>
|
||
</dd>
|
||
<dt>from_user (<a class="reference internal" href="../types/user.html#telethon.tl.types.user" title="telethon.tl.types.user"><code class="xref py py-obj docutils literal notranslate"><span class="pre">user</span></code></a>, <em>可选</em>)</dt><dd><p>指定消息发送者。</p>
|
||
</dd>
|
||
<dt>reverse (<code class="docutils literal notranslate"><span class="pre">bool</span></code>, <em>可选</em>):</dt><dd><p>如果设置为 <code class="docutils literal notranslate"><span class="pre">True</span></code>,则消息将以相反的顺序返回。这意味着 <code class="docutils literal notranslate"><span class="pre">offset_id</span></code> 或者 <code class="docutils literal notranslate"><span class="pre">offset_date</span></code> 参数的含义是相反的。
|
||
<code class="docutils literal notranslate"><span class="pre">min_id</span></code> 等同于 <code class="docutils literal notranslate"><span class="pre">offset_id</span></code> 。</p>
|
||
</dd>
|
||
<dt>reply_to (<code class="docutils literal notranslate"><span class="pre">int</span></code>, <em>可选</em>):</dt><dd><p>返回频道消息的所有评论消息。</p>
|
||
<p>此功能只能用于链接了某个频道的*讨论组*。在其他对话中使用它将抛出 <code class="docutils literal notranslate"><span class="pre">PeridInValiderror</span></code> 错误。</p>
|
||
<p>使用此参数时,<code class="docutils literal notranslate"><span class="pre">filter</span></code> 和 <code class="docutils literal notranslate"><span class="pre">search</span></code> 参数无效,因为 Telegram 的 API 不支持搜索回复中的消息。</p>
|
||
</dd>
|
||
</dl>
|
||
</dd>
|
||
</dl>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">生成器</dt>
|
||
<dd class="field-odd"><p>消息对象 <a class="reference internal" href="../types/message.html#telethon.tl.types.message" title="telethon.tl.types.message"><code class="xref py py-obj docutils literal notranslate"><span class="pre">message</span></code></a></p>
|
||
</dd>
|
||
<dt class="field-even">引发</dt>
|
||
<dd class="field-even"><p><strong>PeridInValiderror</strong> – 此对话不是链接了频道的讨论组。</p>
|
||
</dd>
|
||
</dl>
|
||
<p class="rubric">示例</p>
|
||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="c1"># 从最新消息开始检索</span>
|
||
<span class="k">async</span> <span class="k">for</span> <span class="n">message</span> <span class="ow">in</span> <span class="n">client</span><span class="o">.</span><span class="n">iter_messages</span><span class="p">(</span><span class="n">chat</span><span class="p">):</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">id</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">text</span><span class="p">)</span>
|
||
|
||
<span class="c1"># 从第一条消息开始检索</span>
|
||
<span class="k">async</span> <span class="k">for</span> <span class="n">message</span> <span class="ow">in</span> <span class="n">client</span><span class="o">.</span><span class="n">iter_messages</span><span class="p">(</span><span class="n">chat</span><span class="p">,</span> <span class="n">reverse</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">id</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">text</span><span class="p">)</span>
|
||
|
||
<span class="c1"># 只返回我发送的消息</span>
|
||
<span class="k">async</span> <span class="k">for</span> <span class="n">message</span> <span class="ow">in</span> <span class="n">client</span><span class="o">.</span><span class="n">iter_messages</span><span class="p">(</span><span class="n">chat</span><span class="p">,</span> <span class="n">from_user</span><span class="o">=</span><span class="s1">'me'</span><span class="p">):</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">text</span><span class="p">)</span>
|
||
|
||
<span class="c1"># 通过 Telegram 服务器检索匹配的文本消息</span>
|
||
<span class="k">async</span> <span class="k">for</span> <span class="n">message</span> <span class="ow">in</span> <span class="n">client</span><span class="o">.</span><span class="n">iter_messages</span><span class="p">(</span><span class="n">chat</span><span class="p">,</span> <span class="n">search</span><span class="o">=</span><span class="s1">'hello'</span><span class="p">):</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">id</span><span class="p">)</span>
|
||
|
||
<span class="c1"># 检索特定类型的消息(例如:图片)</span>
|
||
<span class="kn">from</span> <span class="nn">telethon.tl.types</span> <span class="kn">import</span> <span class="n">InputMessagesFilterPhotos</span>
|
||
<span class="k">async</span> <span class="k">for</span> <span class="n">message</span> <span class="ow">in</span> <span class="n">client</span><span class="o">.</span><span class="n">iter_messages</span><span class="p">(</span><span class="n">chat</span><span class="p">,</span> <span class="nb">filter</span><span class="o">=</span><span class="n">InputMessagesFilterPhotos</span><span class="p">):</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">photo</span><span class="p">)</span>
|
||
|
||
<span class="c1"># 检索指定频道消息的评论</span>
|
||
<span class="k">async</span> <span class="k">for</span> <span class="n">message</span> <span class="ow">in</span> <span class="n">client</span><span class="o">.</span><span class="n">iter_messages</span><span class="p">(</span><span class="n">channel</span><span class="p">,</span> <span class="n">reply_to</span><span class="o">=</span><span class="mi">123</span><span class="p">):</span>
|
||
<span class="nb">print</span><span class="p">(</span><span class="n">message</span><span class="o">.</span><span class="n">chat</span><span class="o">.</span><span class="n">title</span><span class="p">,</span> <span class="n">message</span><span class="o">.</span><span class="n">text</span><span class="p">)</span>
|
||
</pre></div>
|
||
</div>
|
||
</dd></dl>
|
||
|
||
</div>
|
||
|
||
|
||
</div>
|
||
|
||
</div>
|
||
<footer>
|
||
|
||
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
|
||
|
||
<a href="get_messages.html" class="btn btn-neutral float-right" title="get_messages()" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
|
||
|
||
|
||
<a href="forward_messages.html" class="btn btn-neutral float-left" title="forward_messages()" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
|
||
|
||
</div>
|
||
|
||
|
||
<hr/>
|
||
|
||
<div role="contentinfo">
|
||
<p>
|
||
|
||
</p>
|
||
</div>
|
||
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
|
||
|
||
</footer>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
</section>
|
||
|
||
</div>
|
||
|
||
|
||
|
||
<script type="text/javascript">
|
||
jQuery(function () {
|
||
SphinxRtdTheme.Navigation.enable(false);
|
||
});
|
||
</script>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
</body>
|
||
</html> |