当定位第二个命令时,运行“ commands.group()”的discord.py发送帮助命令

时间:2020-09-27 18:56:27

标签: discord.py discord.py-rewrite

很难获得完美的称号,但几乎可以做到。弄清楚!!changelog是主要命令,它将发送所有可用命令的列表,但是我得到的问题是。每当我运行!!changelog message <text>命令时,就会显示预设的“帮助”消息。

图片在这里: enter image description here

无论何时发送邮件,我只希望它说“您的邮件已发送”之类的内容。

这是我的代码:

@commands.group(invoke_without_command=True)
async def changelog(self, ctx):
    await ctx.send('Available Setup Commands: \nSet Channel: <#channel>\nChangelog Message: <message>')

@changelog.command()
async def channel(self, ctx, channel: discord.TextChannel):
    if ctx.message.author.guild_permissions.administrator:
        db = sqlite3.connect('main.sqlite')
        cursor = db.cursor()
        cursor.execute(
            f'SELECT channel_id FROM main WHERE guild_id = {ctx.guild.id}')
        result = cursor.fetchone()
        if result is None:
            sql = ('INSERT INTO main(guild_id, channel_id) VALUES(?,?)')
            val = (ctx.guild.id, channel.id)
            await ctx.send(f'Channel has been set to {channel.mention}')
        elif result is not None:
            sql = ('UPDATE main SET channel_id = ? WHERE guild_id = ?')
            val = (channel.id, ctx.guild.id)
            await ctx.send(f'Channel has been updated to {channel.mention}')
        cursor.execute(sql, val)
        db.commit()
        cursor.close()
        db.close()

@changelog.command()
async def message(self, ctx, *, text):
    if ctx.message.author.guild_permissions.manage_messages:
        est = timezone('EST')
        db = sqlite3.connect('main.sqlite')
        cursor = db.cursor()
        cursor.execute(f'SELECT channel_id FROM main WHERE 1')
        channel = cursor.fetchone()
        channel_id = self.client.get_channel(int(channel[0]))
        message = text.capitalize()
        embed = discord.Embed(
            title="Changelog", description=f"● {message}", color=0)
        embed.set_footer(
            text=f'Published: {datetime.now(est).strftime("%Y-%m-%d %H:%M:%S")}')
        await channel_id.send(embed=embed)
        cursor.close()
        db.close()

1 个答案:

答案 0 :(得分:0)

您可以使用ctx.invoked_subcommand来检查组中是否正在运行子命令:

async def changelog(self, ctx):
    if ctx.invoked_subcommand is None:
        await ctx.send('Available Setup Commands: \nSet Channel <#channel>\nChangelog Message: <message>')