i want to to send private messages to all the mentioned users and also store the usernames in a vector. everything works, but the program just keeps on crashing on push_back(), it works in other places but just not inside this lambda. A begineer here, what implementation have i done wrong here?
std::vector<std::string> userNames;
for (int itr = 0; itr < message.mentions.size(); itr++)
{
dpp::snowflake user_id_to_dm = message.mentions[itr].first.id;
bot.direct_message_create(user_id_to_dm, dpp::message("Here's a private message!"),
[event, &bot, message, &userNames, itr] (const dpp::confirmation_callback_t& callback)
{
if (callback.is_error())
{
bot.message_create(dpp::message(event.msg.channel_id,
"I couldn't send a message to " + message.mentions[itr].first.username)
.set_reference(message.id));
return;
}
std::string nameTemp = message.mentions[itr].first.username;
std::cout << "DM Sent to " << nameTemp << "n";
userNames.push_back(nameTemp);
});
}
New contributor
Fangjang is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.