sub getMessages($) { my $apiUrl = $baseUrl . "channels/" . $_[0] . "/messages?limit=1"; print "$apiUrl\n"; my $discordClient = WWW::Mechanize->new( agent => 'DiscordBot (LibDiscord-Perl5 1)' ); $discordClient->add_header('Authorization' => "$authToken"); my $clientConnected = eval { $discordClient->get($apiUrl, 'Content-Type' => 'application/json'); }; if (! $clientConnected ) { errorCon(); } else { # Set values when connection is successful our $apiContent = $discordClient->content; #print Dumper($apiContent) . "\n"; my @apiJson = decode_json( $apiContent ); print "Pretty Response:\n" . Dumper( @apiJson ) . "\n"; my $msgID = $apiJson[0]->{'id'}; my $msgAuthor = $apiJson[0]->{'author'}->{'username'}; my $msgContent = $apiJson[0]->{'content'}; if ($msgID > $lastMsgID) { print "<$msgAuthor> $msgContent\n"; $lastMsgID = $msgID; } } } sub errorCon { print "Error: Unable to connect to Discord!\n"; }