yuuko
yuuko copied to clipboard
Commands as a Map instead of Array.
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");
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)
Oki 👍