为了账号安全,请及时绑定邮箱和手机立即绑定

子命令问题:ctx.invoked_subcommands 始终为 None

子命令问题:ctx.invoked_subcommands 始终为 None

慕的地6264312 2021-06-29 02:33:44
编辑:已找到解决方案尝试将子命令的名称更改为_enabled和_disabled并传递name="enabled" name="disabled"给命令装饰器。这是一个猜测,但有时 Bot 内部使用的名称在用作命令名称时无法正常工作。- 帕特里克·豪我尝试清理一些代码并尝试将子命令实现到模块中,但我遇到了一个似乎无法解决的问题。首先,这里是代码:@commands.group()@commands.has_permissions(administrator=True)async def autorole(self, ctx):    exists = dbinteraction.dbexec("SELECT role from autorole WHERE server_id = {}".format(ctx.guild.id))    if ctx.invoked_subcommand is None:        em = None        if (exists == None):            em = discord.Embed(title="Autorole is disabled for this guild.", color=discord.Color(0xff0000))        else:            em = discord.Embed(title="Autorole is enabled for this guild.", color = discord.Color(0x32ff00))            rol = discord.utils.get(ctx.guild.roles, id=exists)            em.add_field(name="Current role:", value=rol.mention)        await ctx.send(embed=em)@autorole.command()@commands.has_permissions(administrator=True)async def enabled(self, ctx, role: discord.Role=None):    """Defines a role that will be applied to all new members, format: autorole (enabled/disabled) [role]"""    exists = dbinteraction.dbexec("SELECT role from autorole WHERE server_id = {}".format(ctx.guild.id))    print('status, role : {} {}'.format("enabled", role.id))    try:        if role==None:            await ctx.send("No role provided")        else:            if (exists!=None):                dbinteraction.dbexec("UPDATE autorole SET role = {}".format(role.id))            else:                dbinteraction.dbexec("INSERT INTO autorole VALUES({},{})".format(ctx.guild.id, role.id))                em = discord.Embed(title="", color= discord.Color(0x32ff00))                em.add_field(name="Autorole enabled", value="Current role: {}".format(role.mention))                await ctx.send(embed=em)    except (Exception) as e:        print(e)无论我尝试什么,以下代码始终执行默认命令(之后的if ctx.invoked_subcommand is None:),我正在使用重写
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 263 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号