* Inital Docs * Finish Design * Finish Design * Add FILE Structure' * Add Not Ready Template * Update Template * Add Command Manager and first Command ping * Add Command Manager and first Command ping * Add Embeds Guide & EventManager * INITIAL FINISH: GUIDE * FIX TYPOS, LTS's Review, sidebar_position * Update site/docs/nodejs/getting-started.md Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> * Fixed Position? Add some comments on template, add changes in review * Add Interaction Handling, Modals * format files * Update site/docs/nodejs/getting-started.md 1 Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> * Update site/docs/nodejs/CommandHandler/command-manager.md Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> * Fix Review things * itoh's suggestions The guide looks very very veery good overall I like it. This commit adds my personal style of writing. Please review it 🙏. PS: I hope these are not too many changes .-. * deno fmt Co-authored-by: meister03 <root@_HOSTNAME_> Co-authored-by: ITOH <to@itoh.at> Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
1.9 KiB
sidebar_position
| sidebar_position |
|---|
| 5 |
Slash Commands
Since Discord has decided to make message content accessible only to privileged bots, message commands will play a subordinate role in the future. Discord users will be more used to slash commands. That's why it's essential that every bot offers them.
In the following we will show you how to create slash commands:
Deploying Slash Commands
There is a difference between global and guild commands. Global commands take a while to appear in all guilds. Guild commands show up directly.
For this reason, we will now show how to create guild commands, in order to test them immediately.
const guildId = BigInt("YOUR_GUILD_ID");
const command = {
name: "ping",
description: "Retrieves the Bot latency",
options: [],
};
client.helpers.createApplicationCommand(command, guildId);
This is just very simple example, you can also add sub commands, select options and much more.
Handling Slash Commands
Discord sends a WebSocket Event, when a user runs a slash command. You can listen to this event by add the
interactionCreate function in the client.
const Discord = require("discordeno");
const config = require("./config.json");
const client = Discord.createBot({
events: {
ready(client, payload) {
console.log(`Successfully connected Shard ${payload.shardId} to the gateway`);
},
async interactionCreate(client, interaction) {
if (interaction.data?.name === "ping") {
return await client.helpers.sendInteractionResponse(interaction.id, interaction.token, {
type: Discord.InteractionResponseTypes.ChannelMessageWithSource,
data: { content: "🏓 Pong!" },
});
}
},
},
intents: ["Guilds"],
token: config.token,
});
Discord.startBot(client);
The handling may see complicated in the beginning, but as mentioned before, we will introduce structures to make it easier.