NeuroAssassin / Toxic-Cogs

A collection of utility, moderation and fun plugins to Red - Discord Bot.
MIT License
47 stars 38 forks source link

Editor: Use discord.py converters #71

Open laggron42 opened 2 years ago

laggron42 commented 2 years ago

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:

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:

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:

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