Perl LWP Discord Webhook
sub send_msg {
use LWP;
use HTTP::Request;
use Data::Dumper;
use POSIX qw(strftime);
$Data::Dumper::Indent = 1;
$Data::Dumper::Purity = 1;
$Data::Dumper::Terse = 1;
my ($_args) = @_;
my ($_return);
my $_msg = $_args->{'msg'}.' at '.strftime("%Y-%m-%d %H:%M:%S", localtime);
my $_req = HTTP::Request->new(POST => 'https://discord.com/api/webhooks/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX');
$_req->content_type('application/json');
$_req->header("User-Agent" => "Perl DiscordBot");
$_req->content('{"username": "pinger", "content": "'.$_msg.'"}');
my $_ua = LWP::UserAgent->new;
$_return = $_ua->request($_req);
return $_return;
}
last updated september 2023