Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Use discord.py converters #71

Open
laggron42 opened this issue Dec 29, 2021 · 0 comments
Open

Editor: Use discord.py converters #71

laggron42 opened this issue Dec 29, 2021 · 0 comments

Comments

@laggron42
Copy link

Hey, some users are asking me an edit message feature for my Say cog and I redirect them to your cog. However, I noticed it's not really easy to use.

I think this could be made way easier to use by using the discord.Message and typing.Union type hinters in your command.

Why

The current design of the command is as follows:

[p]editmessage <og_channel_id> <og_message_id> <new_message_id|0> <new_message_content|content>

In my opinion, it presents the following problems:

  • It works with IDs only, which requires the used to have the developer mode enabled
  • You can't use message links, which is now the user-friendly way of referencing a message
  • The new_message thing is confusing. Copying from a message to another may be a good idea, but it's complicated to use. You either have to reference another message using the same methods described above, or type the content which must be preceded by a 0.

How it could be better

discord.Message

A message converter was added to discord.py (hehe I made it :D) and supports the following formats:

  • Message link
  • <channel ID>-<message ID> (obtained by holding shift when copying message ID, the old way for discord to reference a message to support)
  • Message ID only, provided the message is in the context channel

That alone makes everything a lot easier for the users, only one argument for referencing the message, without needing the developer mode turned on.

typing.Union

Another great feature that you're already using, but at this point you get what I'm about to say. Make the last argument a union between discord.Message and str. If it fails to parse a message link, last argument will be a simple string.

typing.Optional

Another² great feature, if you want an optional argument preceded by a required argument, you should use this.

The way it works is simple: parse the next word (or quoted sentence), if it fits the required type for the optional parameter, use it, else pass it to the next argument.
With that, you can ditch the 0 thing easily.


In the end, you have two ways of building the command:

  • Using typing.Union
    [p]editmessage <og_message> <existing_message|content>

  • Using typing.Optional
    [p]editmessage <og_message> [existing_message] [content]

The latter could let the user combine an existing message with his own content.

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

No branches or pull requests

1 participant