亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

子命令問題: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 關注
  • 292 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號