• <i id='o38Nm'><tr id='o38Nm'><dt id='o38Nm'><q id='o38Nm'><span id='o38Nm'><b id='o38Nm'><form id='o38Nm'><ins id='o38Nm'></ins><ul id='o38Nm'></ul><sub id='o38Nm'></sub></form><legend id='o38Nm'></legend><bdo id='o38Nm'><pre id='o38Nm'><center id='o38Nm'></center></pre></bdo></b><th id='o38Nm'></th></span></q></dt></tr></i><div id='o38Nm'><tfoot id='o38Nm'></tfoot><dl id='o38Nm'><fieldset id='o38Nm'></fieldset></dl></div>
  • <small id='o38Nm'></small><noframes id='o38Nm'>

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

        <legend id='o38Nm'><style id='o38Nm'><dir id='o38Nm'><q id='o38Nm'></q></dir></style></legend>

        如何在 discord.py cogs 中创建别名?

        时间:2023-09-09

        <i id='5EP2r'><tr id='5EP2r'><dt id='5EP2r'><q id='5EP2r'><span id='5EP2r'><b id='5EP2r'><form id='5EP2r'><ins id='5EP2r'></ins><ul id='5EP2r'></ul><sub id='5EP2r'></sub></form><legend id='5EP2r'></legend><bdo id='5EP2r'><pre id='5EP2r'><center id='5EP2r'></center></pre></bdo></b><th id='5EP2r'></th></span></q></dt></tr></i><div id='5EP2r'><tfoot id='5EP2r'></tfoot><dl id='5EP2r'><fieldset id='5EP2r'></fieldset></dl></div>
          • <bdo id='5EP2r'></bdo><ul id='5EP2r'></ul>

                  <tbody id='5EP2r'></tbody>
                <tfoot id='5EP2r'></tfoot>

                  <legend id='5EP2r'><style id='5EP2r'><dir id='5EP2r'><q id='5EP2r'></q></dir></style></legend>

                  <small id='5EP2r'></small><noframes id='5EP2r'>

                • 本文介绍了如何在 discord.py cogs 中创建别名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我设置了一个 discord.py cog,可以使用了.有一个问题,如何为命令设置别名?我会在下面给你我的代码,看看我还需要做什么:

                  I have a discord.py cog set up, ready to use. There is one issue, how do I set up aliases for commands? I'll give you my code below to see what else I need to do:

                  # Imports
                  from discord.ext import commands
                  import bot  # My own custom module
                  
                  
                  # Client commands
                  class Member(commands.Cog):
                      def __init__(self, client):
                          self.client = client
                  
                      # Events
                      @commands.Cog.listener()
                      async def on_ready(self):
                          print(bot.online)
                  
                      # Commands
                      @commands.command()
                      async def ping(self, ctx):
                          pass
                  
                  
                  # Setup function
                  def setup(client):
                      client.add_cog(Member(client))
                  

                  这种情况下,@commands.command()

                  推荐答案

                  discord.ext.commands.Command 对象有一个 aliases 属性.使用方法如下:

                  discord.ext.commands.Command objects have a aliases attribute. Here's how to use it:

                  @commands.command(aliases=['testcommand', 'testing'])
                  async def test(self, ctx):
                      await ctx.send("This a test command")
                  

                  然后您就可以通过编写 !test!testcommand!testing 来调用您的命令(如果您的命令前缀是!).
                  此外,如果您计划编写日志系统,Context 对象有一个 invoked_with 属性,它将调用命令时使用的别名作为值.

                  You'll then be able to invoke your command by writing !test, !testcommand or !testing (if your command prefix is !).
                  Also, if you plan on coding a log system, Context objects have a invoked_with attribute which takes the aliase the command was invoked with as a value.

                  参考: discord.py 文档

                  如果您只想让您的 cog 管理员,您可以覆盖现有的 cog_check 函数,该函数将在调用来自该 cog 的命令时触发:

                  If you want to make your cog admin only, you can overwrite the existing cog_check function that will trigger when a command from this cog is invoked:

                  from discord.ext import commands
                  from discord.utils import get
                  
                  class Admin(commands.Cog):
                      def __init__(self, bot):
                          self.bot = bot
                  
                      async def check_cog(self, ctx):
                          admin = get(ctx.guild.roles, name="Admin")
                          #False -> Won't trigger the command
                          return admin in ctx.author.role
                  

                  这篇关于如何在 discord.py cogs 中创建别名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:get_user(id) 找不到用户 - 返回无(self bot discord.py) 下一篇:首次完成 Discord Bot 后如何播放下一首歌曲

                  相关文章

                  最新文章

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

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

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

                  <tfoot id='GXgem'></tfoot>