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

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

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

      1. 如何為 discord.py 創(chuàng)建自定義裝飾器?

        How do you create a custom decorator for discord.py?(如何為 discord.py 創(chuàng)建自定義裝飾器?)

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

        • <legend id='jBF07'><style id='jBF07'><dir id='jBF07'><q id='jBF07'></q></dir></style></legend>

              <tfoot id='jBF07'></tfoot>

                • <bdo id='jBF07'></bdo><ul id='jBF07'></ul>
                    <tbody id='jBF07'></tbody>
                • <i id='jBF07'><tr id='jBF07'><dt id='jBF07'><q id='jBF07'><span id='jBF07'><b id='jBF07'><form id='jBF07'><ins id='jBF07'></ins><ul id='jBF07'></ul><sub id='jBF07'></sub></form><legend id='jBF07'></legend><bdo id='jBF07'><pre id='jBF07'><center id='jBF07'></center></pre></bdo></b><th id='jBF07'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='jBF07'><tfoot id='jBF07'></tfoot><dl id='jBF07'><fieldset id='jBF07'></fieldset></dl></div>
                  本文介紹了如何為 discord.py 創(chuàng)建自定義裝飾器?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我正在開發(fā)一個機(jī)器人.對于某個 cog,我希望創(chuàng)建一個自定義檢查裝飾器來檢查運行命令的人是否具有特定角色.角色作為實例變量存儲為角色類.當(dāng)我嘗試運行它時,它不起作用.裝飾器是怎么做的?

                  I am working on a bot. For a certain cog, I wish to create a custom check decorator that checks to see if the person running the command has a certain role. The role is stored as a role class as an instance variable. When I tried running it, it doesn't work. How do you make the decorator?

                  class Moderation(commands.Cog):
                      def __init__(self, bot: commands.Bot):
                          self.bot = bot
                          self.mod_role = None  # Assume there's already a role here
                  
                      class Decorator:
                          @classmethod
                          def requires_mod(cls, func):
                              async def decorator(self, ctx: commands.Context, *args, **kwargs):
                                  if self.mod_role not in ctx.author.roles:
                                      await ctx.send("You do not have permission to use this command")
                                  func(ctx, *args, **kwargs)
                              return decorator
                  
                      @commands.command()
                      @Decorator.requires_mod
                      async def purge(self, ctx: commands.Context, amt: int):
                          await ctx.channel.purge(limit=amt+1)
                          await ctx.send(f":white_check_mark: | Deleted {amt} messages.")
                  

                  推薦答案

                  這個概念被內(nèi)置到 commands 擴(kuò)展中作為 檢查

                  This concept is built into the commands extension as Checks

                  即使是特定于 cog 的檢查,例如 cog_check 不知道 cog 本身:它們都不接收 self 作為參數(shù).

                  Even the cog-specific checks like cog_check aren't aware of the cog itself: none of them receive self as an argument.

                  您需要重寫您的支票,使其不依賴于self.如果您現(xiàn)在知道角色名稱或 ID,或者在創(chuàng)建 Moderation 類時,可以使用內(nèi)置的 has_any_role 檢查.

                  You need to rewrite your check such that it doesn't rely on self. If you know the role names or ids now, or when creating the Moderation class, you can use the built-in has_any_role check.

                  否則最簡單的方法可能是使用 Moderation 的類屬性或全局值來存儲角色:

                  Otherwise the easiest way is probably to use either a class attribute of Moderation or a global value to store the role:

                  from discord.ext import commands
                  
                  def predicate(ctx):
                      return Moderation.mod_role in ctx.author.roles
                  
                  has_mod_role = commands.check(predicate)
                  
                  
                  class Moderation(commands.Cog):
                      mod_role = None 
                  
                      def __init__(bot):
                          self.bot = bot
                          Moderation.mod_role = ... 
                  
                      @commands.command()
                      @has_mod_role
                      async def yourcommand(ctx, ...):
                          ...
                  

                  這篇關(guān)于如何為 discord.py 創(chuàng)建自定義裝飾器?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機(jī)器人?)
                  Discord bot isn#39;t responding to commands(Discord 機(jī)器人沒有響應(yīng)命令)
                  Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關(guān)于我嗎?Discord 機(jī)器人的功能?(不和諧.py))
                  message.channel.id Discord PY(message.channel.id Discord PY)
                  How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機(jī)器人?)
                  discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)

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

                          <tbody id='yH2CS'></tbody>

                        <tfoot id='yH2CS'></tfoot>
                        • <bdo id='yH2CS'></bdo><ul id='yH2CS'></ul>
                          <i id='yH2CS'><tr id='yH2CS'><dt id='yH2CS'><q id='yH2CS'><span id='yH2CS'><b id='yH2CS'><form id='yH2CS'><ins id='yH2CS'></ins><ul id='yH2CS'></ul><sub id='yH2CS'></sub></form><legend id='yH2CS'></legend><bdo id='yH2CS'><pre id='yH2CS'><center id='yH2CS'></center></pre></bdo></b><th id='yH2CS'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='yH2CS'><tfoot id='yH2CS'></tfoot><dl id='yH2CS'><fieldset id='yH2CS'></fieldset></dl></div>
                          • <legend id='yH2CS'><style id='yH2CS'><dir id='yH2CS'><q id='yH2CS'></q></dir></style></legend>
                            主站蜘蛛池模板: 99精品视频在线观看免费播放 | 日韩久久中文字幕 | 91九色porny首页最多播放 | 久久99精品视频 | 国产不卡一区 | 亚洲国产成人精 | 中文在线播放 | 精久久| 国产激情一区二区三区 | 四虎免费视频 | 天堂成人av| 成人精品鲁一区一区二区 | 欧美在线天堂 | 大象视频一区二区 | 欧美 日韩 国产 一区 | 一区二区三区视频在线 | 午夜电影网站 | 一区二区中文 | 福利国产 | 亚洲欧美在线一区 | 国产一级片 | 欧美日本韩国一区二区 | 日韩精品一区二区三区在线观看 | 精品国产一区二区在线 | 日韩av免费在线观看 | 欧美在线成人影院 | 四虎在线视频 | 国产精品国产三级国产a | 99久久精品国产一区二区三区 | 天天操妹子 | 美女黄网站视频免费 | 欧美在线视频网 | 免费看国产精品视频 | 日本a在线 | 国产免费播放视频 | 中文字幕亚洲一区二区三区 | 婷婷久| 成人免费小视频 | av中文字幕在线观看 | 欧美视频区| av在线视 |