| 1 | #!/usr/bin/env perl | ||||||||||
| 2 | 1 | ▶ | use v5.26; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use FindBin; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use lib "$FindBin::Bin/../lib"; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Discord::Client; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | # Configure a bot with one slash command. | ||||||||||
| 10 | my $bot = Discord::Client->new( | ||||||||||
| 11 | token => $ENV{DISCORD_BOT_TOKEN}, | ||||||||||
| 12 | 1 | intents => ['GUILDS'], | |||||||||
| 13 | ); | ||||||||||
| 14 | |||||||||||
| 15 | # Keep the response logic separate from the command's argument declaration. | ||||||||||
| 16 | 1 | ▶ | sub greet { | ||||||||
|
Subroutine
greet: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 17 | 1 | my ($interaction) = @_; | |||||||||
| 18 | 1 | my $name = $interaction->option('name'); | |||||||||
| 19 | |||||||||||
| 20 | # Treat the supplied name as text so it cannot trigger a mention. | ||||||||||
| 21 | 1 | return $interaction->reply( | |||||||||
| 22 | { | ||||||||||
| 23 | content => "Hello, $name!", | ||||||||||
| 24 | allowed_mentions => { parse => [] }, | ||||||||||
| 25 | } | ||||||||||
| 26 | ); | ||||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | # Discord presents and validates the required name argument. | ||||||||||
| 30 | 1 | $bot->command( | |||||||||
| 31 | greet => ( | ||||||||||
| 32 | description => 'Greet someone by name', | ||||||||||
| 33 | options => [ | ||||||||||
| 34 | { | ||||||||||
| 35 | name => 'name', | ||||||||||
| 36 | type => 'string', | ||||||||||
| 37 | description => 'Name to greet', | ||||||||||
| 38 | required => 1, | ||||||||||
| 39 | }, | ||||||||||
| 40 | ], | ||||||||||
| 41 | handler => \&greet, | ||||||||||
| 42 | ), | ||||||||||
| 43 | ); | ||||||||||
| 44 | |||||||||||
| 45 | # Run the bot, or expose its declarations to the deployment script. | ||||||||||
| 46 | 1 | ▶ | $bot->run unless caller; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | 1 | $bot; | |||||||||