編輯:已找到解決方案嘗試將子命令的名稱更改為_enabled和_disabled并傳遞name="enabled" name="disabled"給命令裝飾器。這是一個(gè)猜測,但有時(shí) Bot 內(nèi)部使用的名稱在用作命令名稱時(shí)無法正常工作。- 帕特里克·豪我嘗試清理一些代碼并嘗試將子命令實(shí)現(xiàn)到模塊中,但我遇到了一個(gè)似乎無法解決的問題。首先,這里是代碼:@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)無論我嘗試什么,以下代碼始終執(zhí)行默認(rèn)命令(之后的if ctx.invoked_subcommand is None:),我正在使用重寫
子命令問題:ctx.invoked_subcommands 始終為 None
慕的地6264312
2021-06-29 02:33:44