discord.py running a 'commands.group()' sends the help command, when targeting second command

234 Views Asked by At

Hard to get the title perfect, but pretty much. Got it hooked up that !!changelog is the main command, this will send a list of all the commands available, but issue I am getting is that. Whenever I run the !!changelog message <text> command, the preset "help" message shows up.

Picture here: enter image description here

Whenever the message is sent, I just want it to say something like "Your message has been sent"

Here is my code:

@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

There are 1 best solutions below

0
unex On

You can use ctx.invoked_subcommand to check if you are running a subcommand in your group:

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