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

Commands as a Map instead of Array. #97

Open
NotReallyEight opened this issue Aug 26, 2021 · 2 comments
Open

Commands as a Map instead of Array. #97

NotReallyEight opened this issue Aug 26, 2021 · 2 comments
Labels
changes: api modifies behavior of the public API quality removes something unnecessary or updates code style version: major semver-major, involves breaking change
Milestone

Comments

@NotReallyEight
Copy link

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");
@eritbh eritbh added this to the v3 milestone Aug 26, 2021
@eritbh eritbh added changes: api modifies behavior of the public API quality removes something unnecessary or updates code style version: major semver-major, involves breaking change labels Aug 26, 2021
@eritbh
Copy link
Owner

eritbh commented Aug 26, 2021

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)

@NotReallyEight
Copy link
Author

Oki 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes: api modifies behavior of the public API quality removes something unnecessary or updates code style version: major semver-major, involves breaking change
Projects
None yet
Development

No branches or pull requests

2 participants