Skip to content

Commit

Permalink
CommandAttributes options should be CollectionInterface (#1280)
Browse files Browse the repository at this point in the history
  • Loading branch information
valzargaming authored Jan 19, 2025
1 parent 18c0bb9 commit 1975987
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/Discord/Builders/CommandAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace Discord\Builders;

use Discord\Helpers\Collection;
use Discord\Helpers\CollectionInterface;
use Discord\Parts\Interactions\Command\Command;
use Discord\Parts\Interactions\Command\Option;

Expand All @@ -24,17 +26,17 @@
*
* @since 7.1.0
*
* @property int $type The type of the command, defaults 1 if not set.
* @property string $name 1-32 character name of the command.
* @property ?string[]|null $name_localizations Localization dictionary for the name field. Values follow the same restrictions as name.
* @property ?string $description 1-100 character description for CHAT_INPUT commands, empty string for USER and MESSAGE commands.
* @property ?string[]|null $description_localizations Localization dictionary for the description field. Values follow the same restrictions as description.
* @property \Discord\Helpers\CollectionInterface|Option[]|null $options The parameters for the command, max 25. Only for Slash command (CHAT_INPUT).
* @property ?string $default_member_permissions Set of permissions represented as a bit set.
* @property bool|null $dm_permission Indicates whether the command is available in DMs with the app, only for globally-scoped commands. By default, commands are visible.
* @property ?bool $default_permission Whether the command is enabled by default when the app is added to a guild. SOON DEPRECATED.
* @property ?int $guild_id The optional guild ID this command is for. If not set, the command is global.
* @property bool|null $nsfw Indicates whether the command is age-restricted, defaults to `false`.
* @property int $type The type of the command, defaults 1 if not set.
* @property string $name 1-32 character name of the command.
* @property ?string[]|null $name_localizations Localization dictionary for the name field. Values follow the same restrictions as name.
* @property ?string $description 1-100 character description for CHAT_INPUT commands, empty string for USER and MESSAGE commands.
* @property ?string[]|null $description_localizations Localization dictionary for the description field. Values follow the same restrictions as description.
* @property CollectionInterface|Option[]|null $options The parameters for the command, max 25. Only for Slash command (CHAT_INPUT).
* @property ?string $default_member_permissions Set of permissions represented as a bit set.
* @property bool|null $dm_permission Indicates whether the command is available in DMs with the app, only for globally-scoped commands. By default, commands are visible.
* @property ?bool $default_permission Whether the command is enabled by default when the app is added to a guild. SOON DEPRECATED.
* @property ?int $guild_id The optional guild ID this command is for. If not set, the command is global.
* @property bool|null $nsfw Indicates whether the command is age-restricted, defaults to `false`.
*/
trait CommandAttributes
{
Expand Down Expand Up @@ -257,7 +259,7 @@ public function addOption(Option $option): self
throw new \OverflowException('Command can only have a maximum of 25 options.');
}

$this->options ??= [];
$this->options ??= Collection::for(Option::class, 'name');

$this->options[] = $option;

Expand Down Expand Up @@ -293,7 +295,7 @@ public function removeOption(Option $option): self
*/
public function clearOptions(): self
{
$this->options = [];
$this->options = Collection::for(Option::class, 'name');

return $this;
}
Expand Down

0 comments on commit 1975987

Please sign in to comment.