JDA-Applications / JDA-Utilities

A series of tools and utilities for JDA to assist in bot creation
Apache License 2.0
218 stars 111 forks source link

[Feature] Make CommandEvent cancellable #91

Closed PermissionError closed 5 years ago

PermissionError commented 5 years ago

Issue

Issue Checklist

Please follow the following steps before opening this issue.
Issues that do not complete the checklist may be closed without any help.

The issue tracker is reserved for issues, errors, and feature requests related to JDA-Utilities, and not questions and other requests for help.

Issue Information

Check all that apply:

This issue tracker does not assist or handle issues with the JDA library.
For JDA related issues, visit the JDA issue tracker and open an issue there.

Description

Recently I've been wondering why the CommandEvent is not cancellable. This could have a number of use-cases, primarily in the CommandListener#onCommand method, where a developer could do pre-command checks, and cancel the command execution if needed.

I mainly opened this issue to ask for some advice first, because in my mind this should be a reasonably simple modification to JDA-Utilities that I should be able to contribute, but if there are any problems or difficulties that I have overlooked, please tell me so.

natanbc commented 5 years ago

And how would a cancellable event work? You can just ignore it like a regular JDA event

PermissionError commented 5 years ago

@natanbc In the CommandClientImpl, it calls CommandClient#onCommand before actually executing thhe command. So, if we could do something like CommandEvent#setCancelled in the onCommand method, the CommandClient could then getCancelled, and if true, do not execute the command..

jagrosh commented 5 years ago

You should not be relying on the order events happen; do your checks via a category, and/or utilize exception handling to prevent commands from running