Discord::Client

Build Discord bots in Perl with slash commands, messages, buttons and forms. Uses IO::Async and Future to handle connections and rate limits. Requires Perl 5.26 or newer. The API is experimental.

Unofficial; not affiliated with or endorsed by Discord.

Install

From CPAN:

cpanm Discord::Client

From a source checkout:

cpanm .

A simple bot

use v5.26;
use warnings;
use Discord::Client;

# Create the bot.
my $bot = Discord::Client->new(token => $ENV{DISCORD_BOT_TOKEN});

# Reply to /ping.
$bot->command(
    ping => (
        description => 'Replies with Pong',
        handler => sub {
            my ($interaction) = @_;
            return $interaction->reply('Pong!');
        },
    ),
);

# Run until shutdown.
$bot->run;

Create a bot in the Discord Developer Portal and invite it to a test server with the bot and applications.commands scopes. Leave the Interactions Endpoint URL empty. Set DISCORD_BOT_TOKEN and TEST_GUILD_ID in your environment.

Deploy the ping example once, then run it:

perl examples/sync-commands.pl examples/ping.pl
perl examples/ping.pl

Deployment replaces this application's commands in the test server. Startup does not deploy commands. Try /ping; stop the bot with Ctrl+C.

More

Read the installed API documentation with perldoc Discord::Client.

Apache License 2.0.