Skip to content

Conversation

@krishnans2006
Copy link
Contributor

Note: I didn't create a new application and use it to test the code out, but it's the same code from my other bots, just modified a small bit. If you have some way of testing it out, please do before "publishing" it. 🙂

@CLAassistant
Copy link

CLAassistant commented Feb 12, 2021

CLA assistant check
All committers have signed the CLA.

@oohwooh oohwooh self-requested a review February 12, 2021 19:07
@oohwooh oohwooh self-assigned this Feb 12, 2021
Copy link
Member

@oohwooh oohwooh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the title of the embed could be determined from the bots current name rather than hardcoded that would be preferred

src/cogs/help.py Outdated
async def help(self, context):
fields = [[f"All `{cog}` Commands:", "".join([f" • `{cmd}`\n" for cmd in self.client.get_cog(cog).get_commands()]).rstrip()] for cog in self.cogs]
embed = create_embed(
"John \"Not a robot\" Peter: Help",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible for this to pull from the bots current name? Sometimes we change the name on occasion (this might get more frequent if #19 merged)

src/cogs/help.py Outdated

async def cmd_help(self, client, context, command):
command = get(self.client.commands, name=command)
embed = create_embed("John \"Not a robot\" Peter: Help", description=f"Help with the `{command}` command", fields=[
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question here

src/cogs/help.py Outdated
if get(self.client.commands, name=name):
await self.cmd_help(self.client, context, name)
else:
await context.send(embed=create_embed("John \"Not a robot\" Peter: Help", description=f"The command `{name}` does not exist!"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

@krishnans2006
Copy link
Contributor Author

If the title of the embed could be determined from the bots current name rather than hardcoded that would be preferred

Hmmm I'll try... if not I'll just make it "Help"

@krishnans2006
Copy link
Contributor Author

Does this work? Again - I can't test it but I think it might work

@oohwooh
Copy link
Member

oohwooh commented Feb 12, 2021

Testing it, I get the error:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In embed.fields.0.value: This field is required
In embed.fields.3.value: This field is required

@krishnans2006
Copy link
Contributor Author

Testing it, I get the error:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In embed.fields.0.value: This field is required
In embed.fields.3.value: This field is required

What line of code did you get that from? the error should repeat twice... can you send me the first part of it?

@krishnans2006
Copy link
Contributor Author

Also, I think it might be because all the commands don't have a brief or description, let me try to fix that

@oohwooh
Copy link
Member

oohwooh commented Feb 12, 2021

Here's the full sterr:

Ignoring exception in on_command_error
Traceback (most recent call last):
  File "D:\SRND\johnpeter-discord\venv\lib\site-packages\discord\ext\commands\core.py", line 85, in wrapped
    ret = await coro(*args, **kwargs)
  File "D:\SRND\johnpeter-discord\src\cogs\help.py", line 75, in show_help
    await self.help(context)
  File "D:\SRND\johnpeter-discord\src\cogs\help.py", line 48, in help
    await context.send(embed=embed)
  File "D:\SRND\johnpeter-discord\venv\lib\site-packages\discord\abc.py", line 937, in send
    message_reference=reference)
  File "D:\SRND\johnpeter-discord\venv\lib\site-packages\discord\http.py", line 247, in request
    raise HTTPException(r, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In embed.fields.0.value: This field is required
In embed.fields.3.value: This field is required

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\SRND\johnpeter-discord\venv\lib\site-packages\discord\client.py", line 343, in _run_event
    await coro(*args, **kwargs)
  File "D:/SRND/johnpeter-discord/src/main.py", line 208, in on_command_error
    raise error
  File "D:\SRND\johnpeter-discord\venv\lib\site-packages\discord\ext\commands\bot.py", line 902, in invoke
    await ctx.command.invoke(ctx)
  File "D:\SRND\johnpeter-discord\venv\lib\site-packages\discord\ext\commands\core.py", line 864, in invoke
    await injected(*ctx.args, **ctx.kwargs)
  File "D:\SRND\johnpeter-discord\venv\lib\site-packages\discord\ext\commands\core.py", line 94, in wrapped
    raise CommandInvokeError(exc) from exc
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In embed.fields.0.value: This field is required
In embed.fields.3.value: This field is required

@krishnans2006
Copy link
Contributor Author

Does this help?

@oohwooh
Copy link
Member

oohwooh commented Feb 12, 2021

It appears to work!
image
Not all the commands show up in it, though - part of this is because my testing environment isn't perfect so several cogs need to be disabled, but some of the cogs (like badge) are loaded but don't show up in help - are there decorators or docstrings we need to add to these cogs for them to show up properly with your help function?

Also, the self.client.user portion returns the username+discriminator, if it wouldn't be too much effort to make it give the display_name of the bot in the current guild? (if that's too much effort, this is a super tiny gripe so it really doesn't matter at all)

Also, just as an aside, I was poking around docs and found this: https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#help-commands, which might be a better way of implementing this functionality (although I'm totally fine merging this code, just something i thought worth sharing)

@krishnans2006
Copy link
Contributor Author

It appears to work!
image
Not all the commands show up in it, though - part of this is because my testing environment isn't perfect so several cogs need to be disabled, but some of the cogs (like badge) are loaded but don't show up in help - are there decorators or docstrings we need to add to these cogs for them to show up properly with your help function?

Also, the self.client.user portion returns the username+discriminator, if it wouldn't be too much effort to make it give the display_name of the bot in the current guild? (if that's too much effort, this is a super tiny gripe so it really doesn't matter at all)

Also, just as an aside, I was poking around docs and found this: https://discordpy.readthedocs.io/en/latest/ext/commands/api.html#help-commands, which might be a better way of implementing this functionality (although I'm totally fine merging this code, just something i thought worth sharing)

I used to have an old help command using BotHelpCommand, which I later threw away since I couldn't find a way to put the help command itself in a category... it would say No Category. Maybe try using that? I'll commit in a sec

@oohwooh
Copy link
Member

oohwooh commented Feb 12, 2021

Looks good to merge! I'm getting an error in testing with the gold cog, however I get the same error when running ~help even with the bot.help_command override commented out. So I'll assume it's an issue with my testing environment, will deploy to production and test there! (very good practice, I know)

@oohwooh oohwooh merged commit ba30743 into codeday:master Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants