Sometimes we need to update an object, such as message or channel. At first, it might seem confusing, but it's actually really simple! You just need to use an object with identical properties you don't need to update. NOTE: your bot can't edit messages sent by others.
- Note
- This example uses callback functions. To see more information about them, visit Using Callback Functions.
#include <dpp/dpp.h>
int main() {
event.reply("That's a message");
const auto content = std::get<std::string>(event.get_parameter("content"));
const dpp::snowflake msg_id = std::get<std::string>(event.get_parameter("msg-id"));
bot.message_get(msg_id, event.command.channel_id, [&bot, content, event](const dpp::confirmation_callback_t& callback) {
if (callback.is_error()) {
event.reply("error");
return;
}
auto message = callback.get<dpp::message>();
message.set_content(content);
bot.message_edit(message);
event.reply("Message content is now `" + content + "`.");
});
const auto name = std::get<std::string>(event.
get_parameter(
"name"));
const auto channel_id = std::get<dpp::snowflake>(event.
get_parameter(
"channel"));
event.reply("error");
return;
}
bot.channel_edit(channel);
event.
reply(
"Channel name is now `" + name +
"`.");
});
}
});
if (dpp::run_once <struct register_global_commands>()) {
dpp::slashcommand channel_edit(
"channel-edit",
"Edit the name of channel specified", bot.me.id);
bot.global_bulk_command_create({ msg_edit, channel_edit, msg_send });
}
});
return 0;
}
Before editing:
After editing: