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

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

      <tfoot id='DxqhN'></tfoot>

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

      1. Discord.py 如何在另一个命令中调用另一个命令?

        时间:2023-09-09

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

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

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

                  <tfoot id='EvWoP'></tfoot>
                  本文介绍了Discord.py 如何在另一个命令中调用另一个命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我希望我的机器人在使用已定义的函数 (+play) 键入 +playtest 时播放特定歌曲但我有一个错误说

                  I want my bot to play a specific song when typing +playtest using already defined function (+play) but i got an error says

                  Discord.ext.commands.errors.CommandInvokeError:命令引发了异常:TypeError:命令"对象不可调用"

                  "Discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: 'Command' object is not callable"

                  除此命令外,整个代码都可以正常工作我想知道 ctx.invoke 是否启用传递参数?或者我只是错过了一些东西

                  an entire code work perfectly fine except for this command i wonder does ctx.invoke enable passing arguments? or i just missed something

                  这是我的简短代码

                  import discord
                  import wavelink
                  from discord.ext import commands
                  
                  import asyncio
                  from bs4 import BeautifulSoup
                  import requests
                  import datetime
                  
                  queue = []
                  
                  
                  
                  class Bot(commands.Bot):
                  
                      def __init__(self):
                          super(Bot, self).__init__(command_prefix=['+'])
                  
                          self.add_cog(Music(self))
                  
                      async def on_ready(self):
                          print(f'Logged in as {self.user.name} | {self.user.id}')
                  
                  
                  class Music(commands.Cog):
                  
                      def __init__(self, bot):
                          self.bot = bot
                  
                          if not hasattr(bot, 'wavelink'):
                              self.bot.wavelink = wavelink.Client(bot=self.bot)
                  
                          self.bot.loop.create_task(self.start_nodes())
                          self.bot.remove_command("help")
                  
                      async def start_nodes(self):
                          await self.bot.wait_until_ready()
                  
                          await self.bot.wavelink.initiate_node(host='127.0.0.1',
                                                                port=80,
                                                                rest_uri='http://127.0.0.1:80',
                                                                password='testing',
                                                                identifier='TEST',
                                                                region='us_central')
                  
                      @commands.command(name='connect')
                      async def connect_(self, ctx, *, channel: discord.VoiceChannel = None):
                  
                  
                      @commands.command()
                      async def help(self, ctx):
                  
                      @commands.command()
                      async def play(self, ctx, *, query: str):
                  
                      @commands.command(aliases=['sc'])
                      async def soundcloud(self, ctx, *, query: str):
                  
                  
                      @commands.command()
                      async def leave(self, ctx):
                  
                      @commands.command(aliases=['queue', 'q'])
                      async def check_queue(self, ctx):
                  
                      @commands.command(aliases=['clearq', 'clearqueue'])
                      async def clear_queue(self, ctx):
                  
                  
                      @commands.command(aliases=['removequeue', 'removeq', 'req'])
                      async def remove_queue(self, ctx, num: int):
                  
                      @commands.command()
                      async def skip(self, ctx):
                  
                  
                      @commands.command(aliases=['eq'])
                      async def equalizer(self, ctx: commands.Context, *, equalizer: str):
                  
                      @commands.command()
                      async def playtest(self,ctx):
                         await ctx.invoke(self.play('hi'))
                  
                  bot = Bot()
                  bot.run('sd')
                  

                  推荐答案

                  ctx.invoke 确实允许传递参数,但它们需要以不同于您习惯的方式处理(function(params) )

                  ctx.invoke does allow passing arguments, but they need to be handled in a different way to how you may be used to ( function(params) )

                  参数必须在调用中显式显示(例如 param = 'value')并且命令必须是命令对象.这就是你可以调用命令的方式:

                  The parameters must be explicitly shown in the invoke (e.g. param = 'value') and the command must be a command object. This would be how you could invoke a command:

                  @commands.command()
                  async def playtest(self, ctx):
                     await ctx.invoke(self.bot.get_command('play'), query='hi')
                  

                  这篇关于Discord.py 如何在另一个命令中调用另一个命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:我想让我的 Discord Bot 发送图像/GIF 下一篇:RuntimeError:超时上下文管理器应该在任务内部使用

                  相关文章

                  最新文章

                  <legend id='NsY8D'><style id='NsY8D'><dir id='NsY8D'><q id='NsY8D'></q></dir></style></legend>
                • <tfoot id='NsY8D'></tfoot>
                • <small id='NsY8D'></small><noframes id='NsY8D'>

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

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