<legend id='GbViN'><style id='GbViN'><dir id='GbViN'><q id='GbViN'></q></dir></style></legend>
      • <bdo id='GbViN'></bdo><ul id='GbViN'></ul>
    1. <i id='GbViN'><tr id='GbViN'><dt id='GbViN'><q id='GbViN'><span id='GbViN'><b id='GbViN'><form id='GbViN'><ins id='GbViN'></ins><ul id='GbViN'></ul><sub id='GbViN'></sub></form><legend id='GbViN'></legend><bdo id='GbViN'><pre id='GbViN'><center id='GbViN'></center></pre></bdo></b><th id='GbViN'></th></span></q></dt></tr></i><div id='GbViN'><tfoot id='GbViN'></tfoot><dl id='GbViN'><fieldset id='GbViN'></fieldset></dl></div>

      <small id='GbViN'></small><noframes id='GbViN'>

      <tfoot id='GbViN'></tfoot>
    2. 如何防止用户在频道中发送多条消息?

      时间:2023-10-10

          <legend id='7JmLq'><style id='7JmLq'><dir id='7JmLq'><q id='7JmLq'></q></dir></style></legend>
            <tbody id='7JmLq'></tbody>
        1. <small id='7JmLq'></small><noframes id='7JmLq'>

          <tfoot id='7JmLq'></tfoot>
              <bdo id='7JmLq'></bdo><ul id='7JmLq'></ul>

                <i id='7JmLq'><tr id='7JmLq'><dt id='7JmLq'><q id='7JmLq'><span id='7JmLq'><b id='7JmLq'><form id='7JmLq'><ins id='7JmLq'></ins><ul id='7JmLq'></ul><sub id='7JmLq'></sub></form><legend id='7JmLq'></legend><bdo id='7JmLq'><pre id='7JmLq'><center id='7JmLq'></center></pre></bdo></b><th id='7JmLq'></th></span></q></dt></tr></i><div id='7JmLq'><tfoot id='7JmLq'></tfoot><dl id='7JmLq'><fieldset id='7JmLq'></fieldset></dl></div>
                本文介绍了如何防止用户在频道中发送多条消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                User 1: Hello!
                User 1: How are you?
                User 2: I'm good.
                User 2: hbu
                User 3: hey guys!
                User 1: i'm doing fine
                

                我正在尝试从用户 1 和用户 2 中删除第二条消息,这样任何用户都只能发送一条消息.我被告知要使用 channel.history,但我想不出一种方法来比较消息的作者以确保它们不是同一个人.

                I'm trying to delete the second message from User 1 and User 2, so that any user can only send a single message. I was told to use channel.history, but I can't think of a way to compare the author's of the messages to make sure they aren't the same person.

                这就是我想要的:我想防止重复发布:

                This is what I want: I want to prevent double posting:

                User 1: Hello! How are you?
                User 2: I'm good, hbu.
                User 3: hey guys!
                User 1: i'm doing fine
                

                我只是不知道如何使用 channel.history 来做到这一点.

                I just don't know how to use channel.history to do this.

                推荐答案

                您可以使用 on_message() 事件并将频道历史记录的限制设置为 2:

                You can use the on_message() event and set the channel history's limit to 2 for this:

                @bot.event
                async def on_message(message):
                    recent_author = (await message.channel.history(limit=2).flatten())[1].author
                    if message.author == recent_author:
                        await message.delete()
                

                history() 协程首先获取最新消息,除非另有说明,因此您可以将限制设置为 2 以获取用户刚刚发送的消息之前的最新消息.

                The history() coroutine gets the newest messages first, unless specified otherwise, so you can set the limit to 2 to get the most recent message before the one the user just sent.

                参考资料:

                • Messageable.history()
                • Message.author
                • Message.delete()

                这篇关于如何防止用户在频道中发送多条消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

              • <legend id='HeHnq'><style id='HeHnq'><dir id='HeHnq'><q id='HeHnq'></q></dir></style></legend>
                  <bdo id='HeHnq'></bdo><ul id='HeHnq'></ul>

                      <small id='HeHnq'></small><noframes id='HeHnq'>

                      <i id='HeHnq'><tr id='HeHnq'><dt id='HeHnq'><q id='HeHnq'><span id='HeHnq'><b id='HeHnq'><form id='HeHnq'><ins id='HeHnq'></ins><ul id='HeHnq'></ul><sub id='HeHnq'></sub></form><legend id='HeHnq'></legend><bdo id='HeHnq'><pre id='HeHnq'><center id='HeHnq'></center></pre></bdo></b><th id='HeHnq'></th></span></q></dt></tr></i><div id='HeHnq'><tfoot id='HeHnq'></tfoot><dl id='HeHnq'><fieldset id='HeHnq'></fieldset></dl></div>
                      1. <tfoot id='HeHnq'></tfoot>
                          <tbody id='HeHnq'></tbody>