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

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

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

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

        如何在 discord.py 中使用 cogs?

        How do I use cogs with discord.py?(如何在 discord.py 中使用 cogs?)
          <i id='wgDQg'><tr id='wgDQg'><dt id='wgDQg'><q id='wgDQg'><span id='wgDQg'><b id='wgDQg'><form id='wgDQg'><ins id='wgDQg'></ins><ul id='wgDQg'></ul><sub id='wgDQg'></sub></form><legend id='wgDQg'></legend><bdo id='wgDQg'><pre id='wgDQg'><center id='wgDQg'></center></pre></bdo></b><th id='wgDQg'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='wgDQg'><tfoot id='wgDQg'></tfoot><dl id='wgDQg'><fieldset id='wgDQg'></fieldset></dl></div>

          <tfoot id='wgDQg'></tfoot>

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

          1. <legend id='wgDQg'><style id='wgDQg'><dir id='wgDQg'><q id='wgDQg'></q></dir></style></legend>
              <tbody id='wgDQg'></tbody>

                  <bdo id='wgDQg'></bdo><ul id='wgDQg'></ul>
                  本文介紹了如何在 discord.py 中使用 cogs?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我為 Discord 編寫了一個相當(dāng)大的機器人.它有超過 1000 行代碼.當(dāng)我在 Youtube 和這里??研究如何做到這一點時,似乎沒有任何效果.我想知道是否有人可以解釋如何正確使用齒輪,可能還有照片示例.我可以展示我必須使用的代碼來幫助您理解我想要什么.

                  I have quite a large bot for Discord written up. It has over 1000 lines of code. When I researched how to do it on Youtube and here, nothing seems to be working. I was wondering if someone could explain how to use a cog properly, possibly with photo examples. I can show what code I have to help you understand what I want.

                  舉個例子,我想將我所有的 mod 命令放在一個單獨的文件中,這樣它就更干凈、更有條理了.那么,我該怎么做呢?這是我的代碼示例:

                  An example would be that I want to have all of my mod commands in a separate file, just so its cleaner and more organized. so, how do I go about doing this? Here is an example of my code:

                  Mod 命令我想使用 cog 移動到單獨的文件

                  Mod Commands I want to move to a separate file using a cog

                  我目前擁有的進口商品

                  前綴和目錄

                  調(diào)用令牌 ID - 令牌 ID 在上面,圖中未顯示:

                  Calling token ID - token id is above, not shown in photo:

                  我不確定如何完全啟動一個 cog,還要導(dǎo)入什么,如何調(diào)用文件.我很了解 Java,但我正在嘗試使用 Discord 來提高我的 Python 技能.

                  I am unsure how to start a cog completely, what else to import, how to call the file. I know Java well, but I am trying to work on my python skills with Discord.

                  推薦答案

                  注意:

                  以下內(nèi)容是為較舊的 0.16 版本編寫的,該版本沒有良好的 cogs 文檔.新的 1.0 版本有很好的文檔,并且完全改變了 cogs 的結(jié)構(gòu).如果您使用的是現(xiàn)代版本的 discord.py,你應(yīng)該查閱官方文檔.

                  每個 cog 都有兩部分:一個類和一個 setup 函數(shù).幾乎所有 setup 函數(shù)看起來都一樣:

                  Every cog has two parts: a class and a setup function. Almost all setup functions look the same:

                  def setup(bot):
                      bot.add_cog(Cog(bot))
                  

                  其中 Cog 是 cog 類.

                  where Cog is the cog class.

                  cog 類包含我們所有的命令和事件作為方法.

                  The cog class contains all of our commands and events as methods.

                  您需要進行四個主要的轉(zhuǎn)換才能將您的機器人變成一個齒輪:

                  There are four main transformations that you need to do to change your bot to a cog:

                  1. bot.command 替換為 commands.command(commandsfrom discord.ext import commands)

                  更改函數(shù)的簽名以在開頭包含 self,因為您的所有命令和事件現(xiàn)在都是 cog 類的方法

                  Change the signatures of your functions to include self at the beginning, as all of your commands and events are now methods of the cog class

                  將所有對 bot 的引用改為引用 self.bot

                  Change all references to bot to refer to self.bot instead

                  移除所有 bot.event 裝飾器.您的 cog 中的事件偵聽器僅在名稱上注冊

                  Remove all bot.event decorators. Event listeners from your cog are registered on name alone

                  還有一些陷阱:

                  1. 從 cog 中的任何 on_message 事件中刪除 await bot.process_commands(message).對于任何消息,這應(yīng)該只等待一次.默認(rèn)的 on_message 已經(jīng)為您完成了這項工作.

                  1. Remove await bot.process_commands(message) from any on_message events in your cog. For any message this should only be awaited once. The default on_message does already does this for you.

                  通過 cog 注冊事件不會從您的主文件或其他 cog 中刪除與該事件相關(guān)的其他回調(diào).這意味著您的機器人可以多次響應(yīng) on_member_join 事件,例如,如果您在多個位置定義了該事件的行為.

                  Registering an event through a cog does not remove other callbacks related to that event, from your main file or other cogs. That means that your bot could respond to a on_member_join event multiple times for example, if you have behaviour for that event defined in multiple places.

                  示例

                  假設(shè)您在目錄 src 中有以下 discord.py bot,bot.py:

                  Example

                  Let's say you have the following discord.py bot, bot.py in the directory src:

                  from discord.ext import commands
                  
                  bot = commands.Bot(command_prefix='!')
                  
                  @bot.command(pass_context=True)
                  @commands.has_role("Mod")
                  async def acommand(ctx, argument):
                     await bot.say("Stuff")
                  
                  @bot.event
                  async def on_message(message):
                      print(message.content)
                      await bot.process_commands(message)
                  
                  bot.run("token")
                  

                  然后您將該功能分解為一個 cog src/cogs/maincog.py

                  You then factor that functionality out into a cog src/cogs/maincog.py

                  from discord.ext import commands
                  
                  class MainCog:
                      def __init__(self, bot):
                          self.bot = bot
                  
                      @commands.command(pass_context=True)
                      @commands.has_role("Mod")
                      async def acommand(self, ctx, argument):
                         await self.bot.say("Stuff")        
                  
                      async def on_message(self, message):
                          print(message.content)
                  
                  def setup(bot):
                      bot.add_cog(MainCog(bot))
                  

                  你的 bot.py 文件看起來像

                  And your bot.py file would look like

                  from discord.ext import commands
                  
                  bot = commands.Bot(command_prefix='!')
                  
                  bot.load_extension("cogs.maincog")
                  
                  bot.run("token")
                  

                  請注意,要在 cogs/maincog.py 加載擴展,我們使用 load_extension("cogs.maincog").

                  Note that to load the extension at cogs/maincog.py, we use load_extension("cogs.maincog").

                  Cogs 還允許你定義一些特殊的方法.其中大部分僅在 discord.py-rewrite 并記錄在 here.

                  Cogs also allow you to define some special methods. Most of these are available only in discord.py-rewrite and are documented here.

                  1. __global_check,以前稱為 __check,在每個命令之前運行,并且必須返回 True 才能繼續(xù)執(zhí)行該命令.

                  1. __global_check, formerly __check, runs before every command and must return True for that command to proceed.

                  __local_check 僅在來自此 cog 的命令之前運行.

                  __local_check runs only before commands from this cog.

                  __global_check_once 我相信這類似于 __global_check 只是它只在子命令的情況下檢查一次.我沒用過這么多.

                  __global_check_once I believe that this is similar to __global_check except that it only checks once in the case of subcommands. I haven't used this much.

                  __unload 您可以通過卸載擴展程序,然后重新加載它來實時刷新您的機器人,這樣您就可以在不讓您的機器人離線的情況下更新您的 cogs.當(dāng)您卸載擴展程序或當(dāng)您的機器人停止運行時調(diào)用此方法,以防您需要進行清理.

                  __unload You can live refresh your bot by unloading the extension, then reloading it, allowing you to update your cogs without taking your bot offline. This method is called when you unload the extension, or when your bot stop running, in case you need to do cleanup.

                  __before_invoke__after_invoke 分別在來自該 cog 的每個命令之前和之后運行.

                  __before_invoke and __after_invoke are run before and after every command from this cog, respectively.

                  __error 是來自此 cog 的命令的錯誤處理程序.

                  __error is an error handler for commands from this cog.

                  這篇關(guān)于如何在 discord.py 中使用 cogs?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  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(如何在不重復(fù)導(dǎo)入頂級名稱的情況下構(gòu)造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(分發(fā)帶有已編譯動態(tài)共享庫的 Python 包)

                  <small id='6JM5C'></small><noframes id='6JM5C'>

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

                        <legend id='6JM5C'><style id='6JM5C'><dir id='6JM5C'><q id='6JM5C'></q></dir></style></legend>

                        <tfoot id='6JM5C'></tfoot>

                          • 主站蜘蛛池模板: 在线观看中文字幕 | 91在线一区 | 欧美在线视频二区 | 亚洲毛片 | 国产视频观看 | 国产成人久久精品一区二区三区 | 三区在线 | 久久精品亚洲成在人线av网址 | 蜜桃在线播放 | 免费观看黄色片视频 | 亚洲国产中文在线 | 久久久久久99 | 亚洲一区中文字幕 | 成人国产在线视频 | 国产在线观看av | 欧美日韩中文字幕 | 一区二区三区免费 | 青青草av网站 | 午夜电影福利 | 国产91精品在线 | 在线视频91| www.日本精品 | 久久精品国产一区二区电影 | 免费高清av | 欧美精品成人一区二区三区四区 | 久草在线 | 久久人人爽人人爽人人片av免费 | 羞羞视频免费观看入口 | 欧美精品一区二区三区四区五区 | 懂色av蜜桃av | 国产免费看 | 国产福利在线视频 | 亚洲一区二区三区在线 | 亚洲国产成人精品一区二区 | 国产激情片在线观看 | 亚洲精品免费在线观看 | 国内自拍视频在线观看 | 国产日韩精品一区二区三区 | a级毛片免费高清视频 | 99精品在线 | 国产精品日韩欧美一区二区三区 |