From 5c64264fbd6c3cec84a2dfc0b020263863bcda93 Mon Sep 17 00:00:00 2001 From: usy Date: Tue, 21 Oct 2025 20:06:30 +0100 Subject: [PATCH 1/2] fix: dpp::cluster::register_command with coroutine handler on windows --- include/dpp/cluster.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/include/dpp/cluster.h b/include/dpp/cluster.h index 0e064ce27d..23c704bd8d 100644 --- a/include/dpp/cluster.h +++ b/include/dpp/cluster.h @@ -607,11 +607,12 @@ class DPP_EXPORT cluster { * @return bool Returns `true` if the command was registered successfully, or `false` if * the command with the same name already exists. */ - template - std::enable_if_t, dpp::task>, bool> - register_command(const std::string& name, F&& handler){ + template F> + requires (dpp::awaitable_type::type>) + bool register_command(const std::string& name, F&& handler) { + co_slashcommand_handler_t wrapped = std::forward(handler); std::unique_lock lk(named_commands_mutex); - auto [_, inserted] = named_commands.try_emplace(name, std::forward(handler)); + auto [_, inserted] = named_commands.try_emplace(name, std::move(wrapped)); return inserted; }; #endif From 3e21b57e81b9dd7309d87373e1cebe33dbc9a134 Mon Sep 17 00:00:00 2001 From: usy Date: Wed, 22 Oct 2025 03:41:59 +0100 Subject: [PATCH 2/2] ensure coro return is dpp::task and non-coro return is void --- include/dpp/cluster.h | 16 ++++++++++------ src/dpp/cluster.cpp | 6 ------ 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/include/dpp/cluster.h b/include/dpp/cluster.h index 23c704bd8d..1d09fb4e91 100644 --- a/include/dpp/cluster.h +++ b/include/dpp/cluster.h @@ -587,7 +587,12 @@ class DPP_EXPORT cluster { * @return bool Returns `true` if the command was registered successfully, or `false` if * the command with the same name already exists */ - bool register_command(const std::string& name, const slashcommand_handler_t handler); + template + std::enable_if_t, bool> register_command(const std::string& name, F&& handler) { + std::unique_lock lk(named_commands_mutex); + auto [_, inserted] = named_commands.try_emplace(name, std::forward(handler)); + return inserted; + } /** * @brief Get the number of currently active HTTP(S) requests active in the cluster. @@ -607,14 +612,13 @@ class DPP_EXPORT cluster { * @return bool Returns `true` if the command was registered successfully, or `false` if * the command with the same name already exists. */ - template F> - requires (dpp::awaitable_type::type>) + template + requires (utility::callable_returns, const slashcommand_t&>) bool register_command(const std::string& name, F&& handler) { - co_slashcommand_handler_t wrapped = std::forward(handler); std::unique_lock lk(named_commands_mutex); - auto [_, inserted] = named_commands.try_emplace(name, std::move(wrapped)); + auto [_, inserted] = named_commands.try_emplace(name, std::in_place_type, std::forward(handler)); return inserted; - }; + } #endif /** diff --git a/src/dpp/cluster.cpp b/src/dpp/cluster.cpp index 272e642d81..1888dccdca 100644 --- a/src/dpp/cluster.cpp +++ b/src/dpp/cluster.cpp @@ -638,12 +638,6 @@ cluster& cluster::set_request_timeout(uint16_t timeout) { return *this; } -bool cluster::register_command(const std::string &name, const slashcommand_handler_t handler) { - std::unique_lock lk(named_commands_mutex); - auto [_, inserted] = named_commands.try_emplace(name, handler); - return inserted; -} - bool cluster::unregister_command(const std::string &name) { std::unique_lock lk(named_commands_mutex); return named_commands.erase(name) == 1;