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

    <legend id='TvsQX'><style id='TvsQX'><dir id='TvsQX'><q id='TvsQX'></q></dir></style></legend>
    <tfoot id='TvsQX'></tfoot>

    1. <small id='TvsQX'></small><noframes id='TvsQX'>

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

      使用不帶 cogs 的 discord.py 是否可以實現 OOP?

      Is OOP possible using discord.py without cogs?(使用不帶 cogs 的 discord.py 是否可以實現 OOP?)

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

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

                <tfoot id='suaTg'></tfoot>
                本文介紹了使用不帶 cogs 的 discord.py 是否可以實現 OOP?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                最近幾天,我一直在嘗試將用 discord.py 編寫的不和諧機器人的結構調整為更面向 OOP 的結構(因為周圍有功能并不理想).

                These last few days, I've been trying to adapt the structure of a discord bot written in discord.py to a more OOP one (because having functions lying around isn't ideal).

                但我發現的問題比我想象的要多得多.問題是我想將所有命令封裝到一個單個類中,但我不知道要使用哪些裝飾器以及我必須繼承哪些類以及如何繼承.

                But I have found way more problems that I could have ever expected. The thing is that I want to encapsulate all my commands into a single class, but I don't know what decorators to use and how and which classes I must inherit.

                到目前為止,我所取得的成果是類似于下面的代碼片段.它會運行,但在執行命令時會拋出類似

                What I've achieved so far is code like the snippet down below. It runs, but at the moment of executing a command it throws errors like

                discord.ext.commands.errors.CommandNotFound:命令狀態"沒找到

                discord.ext.commands.errors.CommandNotFound: Command "status" is not found

                我使用的是 Python 3.6.

                I'm using Python 3.6.

                from discord.ext import commands
                
                
                class MyBot(commands.Bot):
                
                    def __init__(self, command_prefix, self_bot):
                        commands.Bot.__init__(self, command_prefix=command_prefix, self_bot=self_bot)
                        self.message1 = "[INFO]: Bot now online"
                        self.message2 = "Bot still online {}"
                
                    async def on_ready(self):
                        print(self.message1)
                
                    @commands.command(name="status", pass_context=True)
                    async def status(self, ctx):
                        print(ctx)
                        await ctx.channel.send(self.message2 + ctx.author)
                
                
                bot = MyBot(command_prefix="!", self_bot=False)
                bot.run("token")
                

                推薦答案

                要注冊命令你應該使用self.add_command(setup),但是你不能有self<setup 方法中的/code> 參數,因此您可以執行以下操作:

                To register the command you should use self.add_command(setup), but you can't have the self argument in the setup method, so you could do something like this:

                from discord.ext import commands
                    
                class MyBot(commands.Bot):
                    
                    def __init__(self, command_prefix, self_bot):
                        commands.Bot.__init__(self, command_prefix=command_prefix, self_bot=self_bot)
                        self.message1 = "[INFO]: Bot now online"
                        self.message2 = "Bot still online"
                        self.add_commands()
                    
                    async def on_ready(self):
                        print(self.message1)
                    
                    def add_commands(self):
                        @self.command(name="status", pass_context=True)
                        async def status(ctx):
                            print(ctx)
                            await ctx.channel.send(self.message2, ctx.author.name)
                        
                        self.add_command(status)
                    
                bot = MyBot(command_prefix="!", self_bot=False)
                bot.run("token")
                

                這篇關于使用不帶 cogs 的 discord.py 是否可以實現 OOP?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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 - 自動更改角色顏色)
                <legend id='D7z3h'><style id='D7z3h'><dir id='D7z3h'><q id='D7z3h'></q></dir></style></legend>
                <i id='D7z3h'><tr id='D7z3h'><dt id='D7z3h'><q id='D7z3h'><span id='D7z3h'><b id='D7z3h'><form id='D7z3h'><ins id='D7z3h'></ins><ul id='D7z3h'></ul><sub id='D7z3h'></sub></form><legend id='D7z3h'></legend><bdo id='D7z3h'><pre id='D7z3h'><center id='D7z3h'></center></pre></bdo></b><th id='D7z3h'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='D7z3h'><tfoot id='D7z3h'></tfoot><dl id='D7z3h'><fieldset id='D7z3h'></fieldset></dl></div>

                1. <tfoot id='D7z3h'></tfoot>
                          <tbody id='D7z3h'></tbody>

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

                        • <small id='D7z3h'></small><noframes id='D7z3h'>

                        • 主站蜘蛛池模板: 亚洲综合在线一区 | 91精品国产自产精品男人的天堂 | 欧美日韩在线一区二区 | 超碰人人艹 | 永久免费av | 久久99国产精品 | 99在线播放 | 国产色99精品9i | 国产综合av | 玖玖久久| 黄色大片在线播放 | 在线一区二区三区 | 国产成人久久精品 | 日韩一区二区三区av | 国产欧美在线 | 成人精品免费视频 | 91影院 | 国产精品毛片一区二区三区 | 久久精品小视频 | 日韩精品一区二区三区视频播放 | 日本在线观看网址 | 美女久久久久久久 | 天天躁日日躁aaaa视频 | 久久99精品久久久 | 羞羞视频网站 | 欧美高清免费 | 玖玖国产精品视频 | 国产成人福利在线观看 | 四虎最新| 国产999精品久久久久久 | 91精品国产一区二区三区 | 日韩高清在线 | 一级片在线视频 | 中文字字幕一区二区三区四区五区 | 国产精品成人国产乱一区 | 欧美电影在线观看网站 | 日本精品在线一区 | 一区二区三区高清 | 亚洲综合久久精品 | 九九热精品在线视频 | 亚洲国产精品一区二区久久 |