久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

    <tfoot id='zbzIK'></tfoot>
      <bdo id='zbzIK'></bdo><ul id='zbzIK'></ul>

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

        為什么多個 on_message 事件不起作用?

        Why doesn#39;t multiple on_message events work?(為什么多個 on_message 事件不起作用?)
        <i id='wHXld'><tr id='wHXld'><dt id='wHXld'><q id='wHXld'><span id='wHXld'><b id='wHXld'><form id='wHXld'><ins id='wHXld'></ins><ul id='wHXld'></ul><sub id='wHXld'></sub></form><legend id='wHXld'></legend><bdo id='wHXld'><pre id='wHXld'><center id='wHXld'></center></pre></bdo></b><th id='wHXld'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='wHXld'><tfoot id='wHXld'></tfoot><dl id='wHXld'><fieldset id='wHXld'></fieldset></dl></div>
        <tfoot id='wHXld'></tfoot>
            <tbody id='wHXld'></tbody>

              • <bdo id='wHXld'></bdo><ul id='wHXld'></ul>

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

                <legend id='wHXld'><style id='wHXld'><dir id='wHXld'><q id='wHXld'></q></dir></style></legend>
                1. 本文介紹了為什么多個 on_message 事件不起作用?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  為什么我不能有多個 on_message 事件?

                  Why can't I have multiple on_message events?

                  import discord
                  
                  client = discord.Client()
                  
                  @client.event
                  async def on_ready():
                      print('in on_ready')
                  
                  @client.event
                  async def on_message(message):
                      print("in on_message #1")
                  
                  @client.event
                  async def on_message(message):
                      print("in on_message #2")
                  
                  @client.event
                  async def on_message(message):
                      print("in on_message #3")
                  
                  client.run("TOKEN")
                  

                  例如,如果我輸入了任何不和諧的內容,它總是只有最后一個 on_message 被觸發.我怎樣才能讓這三個都工作?

                  For example, if I typed anything in discord, it's always only the last on_message that gets triggered. How can I get all three to work?

                  推薦答案

                  原生Client

                  是不行的

                  你只能有一個 on_message,如果你有多個,on_message事件只會調用最后一個.你只需要結合你的三個 on_message.

                  It's not possible with the native Client

                  You can only have one on_message, if you have multiple, only the last one will be called for the on_message event. You'll just need to combine your three on_message.

                  import discord
                  
                  client = discord.Client()
                  
                  @client.event
                  async def on_message(message):
                      print("in on_message #1")
                      print("in on_message #2")
                      print("in on_message #3")
                  
                  client.run("TOKEN")
                  

                  與任何 Python 變量/函數一樣(除非裝飾器存儲您的函數,@client.event 僅保留最近的回調),如果多個名稱相同,則最近的將被保留,所有其他的都會被覆蓋.

                  Like any Python variable/function (unless the decorator stores your function, @client.event does it by keeping only the most recent callback), if multiple names are the same, the most recently will be kept, and all others will get overwritten.

                  這是我編寫的一個簡單示例,旨在讓您廣泛了解 discord.py 中的事件如何工作(注意:實際代碼與此不完全相同,因為它已被重寫并顯著減少).

                  This is a simple example I wrote to give you a broad understanding of how events in discord.py work (note: the actual code isn't exactly like this, as it's rewritten and significantly reduced).

                  class Client:
                      def event(self, func):               
                          if func.__name__ == "on_message":
                              self.on_message_handle = func
                              return func
                  
                      def receive_message(self, msg):
                          func = getattr(self, "on_message_handle", None)
                          if func is not None:
                              func(msg)
                          else:
                              self.process_commands(msg)
                  
                  client = Client()
                  
                  @client.event
                  def on_message(msg):
                      print("in on_message #1")
                  
                  @client.event
                  def on_message(msg):
                      print("in on_message #2")
                  
                  client.receive_message("hello")
                  # "in on_message #2"
                  

                  如您所見,client.event 只保留一個 on_message 實例.

                  As you can see client.event only keep one instance of on_message.

                  或者,如果您使用 discord.py 的 ext.commands 擴展,則可以通過本機方式獲得多個 on_message 回調.您可以通過將它們定義為 listener 來實現.您最多可以有一個 on_message 事件和無限數量的 on_message 偵聽器.

                  Alternatively, if you're using the ext.commands extension of discord.py, there is a native way to have multiple on_message callbacks. You do so by using defining them as a listener. You can have at most one on_message event, and infinite amounts of on_message listeners.

                  from discord.ext import commands
                  
                  bot = commands.Bot('.')
                  
                  @bot.event
                  async def on_message(msg):
                      print("in on_message #1")
                      await bot.process_commands(msg)  # so `Command` instances will still get called
                  
                  
                  @bot.listen()
                  async def on_message(msg):
                      print("in on_message #2")
                  
                  
                  @bot.listen()
                  async def on_message(msg):
                      print("in on_message #3")
                  
                  bot.run("TOKEN")
                  

                  收到消息后,所有on_message #1-3都會被打印出來.

                  When a message is received, all on_message #1-3 will all get printed.

                  這篇關于為什么多個 on_message 事件不起作用?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                  【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                  相關文檔推薦

                  python: Two modules and classes with the same name under different packages(python:不同包下同名的兩個模塊和類)
                  Configuring Python to use additional locations for site-packages(配置 Python 以使用站點包的其他位置)
                  How to structure python packages without repeating top level name for import(如何在不重復導入頂級名稱的情況下構造python包)
                  Install python packages on OpenShift(在 OpenShift 上安裝 python 包)
                  How to refresh sys.path?(如何刷新 sys.path?)
                  Distribute a Python package with a compiled dynamic shared library(分發帶有已編譯動態共享庫的 Python 包)

                    <bdo id='GcraO'></bdo><ul id='GcraO'></ul>

                      <tbody id='GcraO'></tbody>

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

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

                            <legend id='GcraO'><style id='GcraO'><dir id='GcraO'><q id='GcraO'></q></dir></style></legend>
                          • 主站蜘蛛池模板: 久久精品久久久久久 | 国产综合久久久久久鬼色 | 欧美国产日韩在线观看 | 亚洲高清一区二区三区 | 日韩综合网 | 欧美一区二区在线观看 | 日韩第一页 | 2019精品手机国产品在线 | 中文字幕在线免费 | 激情久久网 | av片在线免费看 | 免费毛片网站在线观看 | 99re6热在线精品视频播放 | 亚洲国产视频一区 | 亚洲激情av | www亚洲一区 | 中文字幕日韩欧美一区二区三区 | 337p日本欧洲亚洲大胆 | 国产国拍亚洲精品av | 中文字幕高清 | 成人影视网| 亚洲国产一区二区三区在线观看 | 欧美激情区 | 久久久久久久久久影视 | 337p日本欧洲亚洲大胆鲁鲁 | 精品欧美一区二区在线观看 | 精品日本久久久久久久久久 | 中文字幕国产精品 | 久久免费视频观看 | 久久久久久免费毛片精品 | 亚洲综合资源 | 亚洲欧美中文日韩在线v日本 | 欧美日韩视频在线第一区 | 欧美精品一区在线发布 | 91精品国产色综合久久不卡98口 | 欧美一级高清片 | 国产伦精品一区二区三区精品视频 | 国产成人啪免费观看软件 | 亚洲av一级毛片 | aa级毛片毛片免费观看久 | 日韩91 |