• <tfoot id='TuLSl'></tfoot>
    1. <small id='TuLSl'></small><noframes id='TuLSl'>

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

        如何让我的 Python Discord 机器人检查消息是否由机

        时间:2023-10-11

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

            <tfoot id='442nB'></tfoot>
                <bdo id='442nB'></bdo><ul id='442nB'></ul>
                <legend id='442nB'><style id='442nB'><dir id='442nB'><q id='442nB'></q></dir></style></legend>

                    <tbody id='442nB'></tbody>
                  本文介绍了如何让我的 Python Discord 机器人检查消息是否由机器人本身发送?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用 Python (v. 3.6.1) 编写一个 Discord 机器人,它检测在一个频道中发送的所有消息并在同一频道中回复它们.但是,机器人会自行回复消息,从而导致无限循环.

                  I am writing a Discord bot using Python (v. 3.6.1) which detects all messages sent in a channel and replies to them in that same channel. However, the bot replies to messages by itself, causing an infinite loop.

                  @bot.event
                  async def on_message(message)
                      await bot.send_message(message.channel, message.content)```
                  

                  我该如何解决这个问题?

                  How would I fix this?

                  推荐答案

                  message 类包含有关消息的 author,您可以使用它来确定是否回复消息.作者 是 会员 对象(或其超类 User 如果频道是私有的),它具有 id 属性,但也支持用户之间的直接逻辑比较.

                  The message class contains information on the message's author, which you can utilize to determine whether or not to respond to the message. author is a Member object (or its superclass User if the channel is private), which has an id property but also supports direct logical comparisons between users.

                  例如:

                  @bot.event
                  async def on_message(message):
                      if message.author != bot.user:
                          await bot.send_message(message.channel, message.content)
                  

                  应该按需要发挥作用

                  这篇关于如何让我的 Python Discord 机器人检查消息是否由机器人本身发送?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何使用 discord.py 按 ID 删除特定消息 下一篇:ModuleNotFoundError:没有名为“不和谐"的模块

                  相关文章

                  最新文章

                      <legend id='B1qru'><style id='B1qru'><dir id='B1qru'><q id='B1qru'></q></dir></style></legend>

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

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