yuuko icon indicating copy to clipboard operation
yuuko copied to clipboard

Commands as a Map instead of Array.

Open NotReallyEight opened this issue 4 years ago • 2 comments

Putting it here, so it could be useful to remember. Making the client.commands as a map, this can be really good when getting a command by name for example, so instead of doing:

const command = client.commands.find(cmd => cmd.names[0].toLowerCase() === "commandname");

you can just do:

const command = client.commands.get("commandname");

NotReallyEight avatar Aug 26 '21 14:08 NotReallyEight

fwiw client.commandForName(name) does already exist as a helper to get a command by name, but it's just a convenience wrapper around the .find() method. Using a map internally would remove the need for that helper and would probably mean better performance when doing command lookups. (maybe i should try benchmarking this)

eritbh avatar Aug 26 '21 14:08 eritbh

Oki 👍

NotReallyEight avatar Aug 26 '21 14:08 NotReallyEight