-
-
Notifications
You must be signed in to change notification settings - Fork 240
Slash Command
SQKo edited this page Jun 25, 2022
·
19 revisions
Formerly known as slash commands, DiscordPHP v7+ supports all types of Discord Application Commands
Here is the example of /ping
command:
use Discord\Parts\Interactions\Command\Command; // Notice to use this correct namespace!
$discord->on('ready', function (Discord $discord) {
// When bot is ready, attempt to create a global slash command
$command = new Command($discord, ['name' => 'ping', 'description' => 'Pong!']);
$discord->application->commands->save($command);
});
// Handle the command
$discord->listenCommand('ping', function (Interaction $interaction) {
// Respond the /ping command with interaction message "pong!"
$interaction->respondWithMessage(MessageBuilder::new()->setContent('pong!'));
});
For more information about Interaction
, see the documentation.
Note: In order for your global application command to show up in a guild, you must authorize the Bot using applications.commands
scope, the URL can be generated from Discord Developers Portal
And then you can double check the command in Server Settings > Integrations
Note: This wiki is currently Work In Progress. Consider reading the docs instead.
- Application Command (Slash based)
Command Client (Message based)
- Activity
- Application
- Guild
- Private Channel
- User
Components
-
ActionRow
- Buttons
- Option (commands)
- SelectMenu
- TextInput
Builders