| 1 | #!/usr/bin/env perl | ||||||||||
| 2 | 2 | ▶ | use v5.26; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | ▶ | use FindBin; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 2 | ▶ | use lib "$FindBin::Bin/../lib"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 2 | ▶ | use Discord::Client; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 2 | ▶ | use Discord::Client::UI qw(row button); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | # Configure a bot whose message contains a button. | ||||||||||
| 11 | my $bot = Discord::Client->new( | ||||||||||
| 12 | token => $ENV{DISCORD_BOT_TOKEN}, | ||||||||||
| 13 | 2 | intents => ['GUILDS'], | |||||||||
| 14 | ); | ||||||||||
| 15 | |||||||||||
| 16 | # Send a button using named properties rather than numeric component types. | ||||||||||
| 17 | $bot->command( | ||||||||||
| 18 | button => ( | ||||||||||
| 19 | description => 'Show a button', | ||||||||||
| 20 | 2 | ▶ | handler => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 2 | my ($interaction) = @_; | |||||||||
| 22 | |||||||||||
| 23 | # Build the visible control with the same ID registered by the component handler. | ||||||||||
| 24 | 2 | return $interaction->reply( | |||||||||
| 25 | { | ||||||||||
| 26 | content => 'Press the button.', | ||||||||||
| 27 | components => [ row( button( 'hello', label => 'Say hello' ) ) ], | ||||||||||
| 28 | } | ||||||||||
| 29 | ); | ||||||||||
| 30 | }, | ||||||||||
| 31 | 2 | ), | |||||||||
| 32 | ); | ||||||||||
| 33 | |||||||||||
| 34 | # The button ID connects the displayed control to its handler. | ||||||||||
| 35 | $bot->component( | ||||||||||
| 36 | 2 | ▶ | hello => sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 37 | 2 | my ($interaction) = @_; | |||||||||
| 38 | |||||||||||
| 39 | # Keep the button response private to the person who clicked it. | ||||||||||
| 40 | 2 | return $interaction->reply( 'Hello!', ephemeral => 1 ); | |||||||||
| 41 | } | ||||||||||
| 42 | 2 | ); | |||||||||
| 43 | |||||||||||
| 44 | # Run the bot, or expose its declarations to the deployment script. | ||||||||||
| 45 | 2 | ▶ | $bot->run unless caller; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | 2 | $bot; | |||||||||