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

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

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

    <tfoot id='fcfzQ'></tfoot>

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

      1. 為多個機器人加載 cog

        Load cog for multiple bots(為多個機器人加載 cog)
          <bdo id='EnxrR'></bdo><ul id='EnxrR'></ul>

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

              <tfoot id='EnxrR'></tfoot>
              <i id='EnxrR'><tr id='EnxrR'><dt id='EnxrR'><q id='EnxrR'><span id='EnxrR'><b id='EnxrR'><form id='EnxrR'><ins id='EnxrR'></ins><ul id='EnxrR'></ul><sub id='EnxrR'></sub></form><legend id='EnxrR'></legend><bdo id='EnxrR'><pre id='EnxrR'><center id='EnxrR'></center></pre></bdo></b><th id='EnxrR'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='EnxrR'><tfoot id='EnxrR'></tfoot><dl id='EnxrR'><fieldset id='EnxrR'></fieldset></dl></div>
                <tbody id='EnxrR'></tbody>
              <legend id='EnxrR'><style id='EnxrR'><dir id='EnxrR'><q id='EnxrR'></q></dir></style></legend>
                • 本文介紹了為多個機器人加載 cog的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  使用 discord.py,我可以從一段代碼運行多個機器人,但我正在尋找一種將 cog 或擴展加載到多個機器人中的方法.對于一個測試用例,我有 bot.py,它處理加載 cog 和啟動 bot,以及 cog.py,它是一個簡單的 cog,它遞增 1 到 a計數器

                  Using discord.py, I can run multiple bots from one piece of code, but I'm looking for a way to load a cog or extension into multiple bots. For a test case, I have bot.py, which handles loading the cog and starting the bot, and cog.py which is a simple cog that incrementally adds 1 to a counter

                  bot.py

                  from discord.ext import commands
                  import asyncio
                  
                  client1 = commands.Bot(command_prefix='!')
                  client2 = commands.Bot(command_prefix='~')
                  
                  client1.load_extension('cog')
                  client2.load_extension('cog')
                  
                  @client1.event
                  async def on_ready():
                      print('client1 ready')
                  
                  @client1.command()
                  async def ping():
                      await client1.say('Pong')
                  
                  @client2.event
                  async def on_ready():
                      print('client2 ready')
                  
                  @client2.command()
                  async def ping():
                      await client2.say('Pong')
                  
                  loop = asyncio.get_event_loop()
                  loop.create_task(client1.start('TOKEN1'))
                  loop.create_task(client2.start('TOKEN2'))
                  loop.run_forever()
                  

                  cog.py

                  from discord.ext import commands
                  
                  class TestCog:
                  
                      def __init__(self, bot):
                          self.bot = bot
                          self.counter = 0
                  
                      @commands.command()
                      async def add(self):
                          self.counter += 1
                          await self.bot.say('Counter is now %d' % self.counter)
                  
                  
                  def setup(bot):
                      bot.add_cog(TestCog(bot))
                  

                  使用 !ping 將使 client1 響應 Pong,而使用 ~ping 將使 client2 響應Pong,這是預期的行為.

                  Using !ping will make client1 respond with Pong, while using ~ping will make client2 respond with Pong, which is expected behaviour.

                  但是,只有一個機器人會同時響應 !add~add,計數器會隨著任一命令而增加.這似乎取決于哪個機器人最后加載 cog.

                  However, only one of the bots will respond to both !add and ~add, with the counter increasing with either command. This seems dependent on which bot loads the cog last.

                  有沒有辦法讓正確的機器人響應正確的命令,同時通過任一命令增加計數器?我知道我可以將它分成兩個齒輪并將結果保存到一個文件中,但是是否可以在不將計數器保存到磁盤的情況下做到這一點?

                  Is there a way to have the correct bot respond to the correct command while also having the counter increase with either command? I know I can split it into two cogs and save the result to a file for example, but is it possible to do it without saving the counter to disk?

                  推薦答案

                  這是因為 @commands.command() 只加載了一次.因此,兩個機器人共享相同的 Command 實例.您需要在實例級別添加命令,而不是通過 @commands.command() 裝飾器.

                  This is due to the fact that @commands.command() is only loaded once. Therefore, both of the bots shared the same Command instance. What you need is to add the command on an instance level, and not by the @commands.command() decorator.

                  class TestCog:
                      counter = 0
                  
                      def __init__(self, bot):
                          self.bot = bot
                          self.bot.add_command(commands.Command('add', self.add))
                  
                      async def add(self):
                          TestCog.counter += 1
                          await self.bot.say('Counter is now %d' % TestCog.counter)
                  

                  或:

                  class TestCog:
                      counter = 0
                  
                      def __init__(self, bot):
                          self.bot = bot
                          self.bot.command()(self.add)
                  
                      async def add(self):
                          TestCog.counter += 1
                          await self.bot.say('Counter is now %d' % TestCog.counter)
                  

                  為了讓兩個機器人共享相同的屬性.你想要的是類屬性,而不是實例的.

                  In order to make both bots share the same attribute. You want class attribute, not instance's.

                  這篇關于為多個機器人加載 cog的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

                  相關文檔推薦

                  How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                  Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                  Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                  message.channel.id Discord PY(message.channel.id Discord PY)
                  How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                  discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)
                  <i id='iWYpL'><tr id='iWYpL'><dt id='iWYpL'><q id='iWYpL'><span id='iWYpL'><b id='iWYpL'><form id='iWYpL'><ins id='iWYpL'></ins><ul id='iWYpL'></ul><sub id='iWYpL'></sub></form><legend id='iWYpL'></legend><bdo id='iWYpL'><pre id='iWYpL'><center id='iWYpL'></center></pre></bdo></b><th id='iWYpL'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='iWYpL'><tfoot id='iWYpL'></tfoot><dl id='iWYpL'><fieldset id='iWYpL'></fieldset></dl></div>

                  • <tfoot id='iWYpL'></tfoot>

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

                        <tbody id='iWYpL'></tbody>
                          • <bdo id='iWYpL'></bdo><ul id='iWYpL'></ul>

                            <legend id='iWYpL'><style id='iWYpL'><dir id='iWYpL'><q id='iWYpL'></q></dir></style></legend>
                            主站蜘蛛池模板: 神马久久久久久久久久 | 在线播放精品视频 | 99亚洲精品| 成人做爰69片免费观看 | 久久国内精品 | 999久久久久久久久6666 | 欧美日韩亚洲国产 | 日本一级淫片免费啪啪3 | 欧美一级欧美三级在线观看 | 一区二区三区四区视频 | 亚洲一二三区av | 一级电影免费看 | 中文字幕精品一区二区三区在线 | 成人精品高清 | 久操伊人 | 亚洲一区二区三区四区五区中文 | 亚洲高清在线 | 激情91| 在线播放国产一区二区三区 | 精品9999| 亚洲精品一区二区三区在线 | 黄网站在线观看 | 国产伦一区二区三区视频 | 一区二区视频在线 | 亚洲va欧美va人人爽午夜 | 精品国偷自产在线 | 免费看色 | 亚洲综合区 | www性色| 午夜黄色 | 日本xx视频免费观看 | www.4567 | 日韩理论电影在线观看 | 天堂网色| 草草视频在线观看 | 国产免费一区二区三区最新6 | 天天射天天干 | www.青青草 | 亚洲免费在线 | 欧美阿v| 国产欧美日韩一区 |