AnyEvent-Discord-Client
view release on metacpan or search on metacpan
lib/AnyEvent/Discord/Client.pm view on Meta::CPAN
!defined $data ? undef
: ref $data ? encode_json($data)
: $data
),
));
if (!$resp->is_success) {
return undef;
}
if ($resp->header("Content-Type") eq 'application/json') {
return JSON::decode_json($resp->decoded_content);
} else {
return 1;
}
}
sub websocket_send {
my ($self, $op, $d) = @_;
die "no connection!" unless $self->{conn};
$self->{conn}->send(encode_json({op=>$op, d=>$d}));
lib/AnyEvent/Discord/Client.pm view on Meta::CPAN
# register "!hello" command
'hello' => sub {
my ($bot, $args, $msg, $channel, $guild) = @_;
$bot->say($channel->{id}, "hi, $msg->{author}{username}!");
},
);
=item C<api(I<$method>, I<$path>, I<$data>, I<$cb>)>
Invokes the Discord API asynchronously and returns immediately. C<$method> is the HTTP method to use; C<$path> is the endpoint to call. If C<$data> is a reference, it is sent as JSON; otherwise, if it is defined, it is sent as a C<x-www-form-urlenc...
=item C<api_sync(I<$method>, I<$path>, I<$data>)>
Invokes the Discord API synchronously and returns the result of the call. C<$method> is the HTTP method to use; C<$path> is the endpoint to call. If C<$data> is a reference, it is sent as JSON; otherwise, if it is defined, it is sent as a C<x-www-f...
=item C<websocket_send(I<$op>, I<$d>)>
Sends a raw WebSocket payload as per the L<Discord Gateway|https://discordapp.com/developers/docs/topics/gateway> documentation.
=back
=head1 AUTHOR
Eric Wastl, C<< <topaz at cpan.org> >>
( run in 0.335 second using v1.01-cache-2.11-cpan-26ccb49234f )