From 345e2407e4f9d42eb913154c0945e632de13d353 Mon Sep 17 00:00:00 2001 From: brain Date: Wed, 29 Jun 2022 18:00:10 +0100 Subject: [PATCH] fix: allow slash commands in dm, fixes #418 --- src/dpp/slashcommand.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/dpp/slashcommand.cpp b/src/dpp/slashcommand.cpp index 9ae30245a3..861b70a88c 100644 --- a/src/dpp/slashcommand.cpp +++ b/src/dpp/slashcommand.cpp @@ -561,6 +561,7 @@ void from_json(const nlohmann::json& j, interaction& i) { i.token = string_not_null(&j, "token"); i.version = int8_not_null(&j, "version"); if (j.contains("member") && !j.at("member").is_null()) { + /* Command invoked from a guild */ if (j.at("member").contains("user") && !j.at("member").at("user").is_null()) { j.at("member").at("user").get_to(i.usr); /* Caching is on; store user if needed */ @@ -584,6 +585,11 @@ void from_json(const nlohmann::json& j, interaction& i) { g->members[i.member.user_id] = i.member; } } + } else if (j.at("user") && !j.at("user").is_null()) { + /* Command invoked from a DM */ + j.at("user").get_to(i.usr); + i.member.user_id = i.usr.id; + i.member.guild_id = 0; } if (j.contains("data") && !j.at("data").is_null()) {