const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessages,
],
});
const BOT_TOKEN = 'YOUR_BOT_TOKEN';
const commands = [
{
name: 'ping',
description: 'Ping pong!',
options: [
{
name: 'secret',
description: 'Secret code',
type: 'STRING',
required: true,
},
],
},
];
client.once('ready', async () => {
console.log(`Logged in as ${client.user.tag}!`);
// Register slash commands globally
const application = await client.application.fetch();
await application.commands.set(commands);
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;
const { commandName, options } = interaction;
if (commandName === 'ping') {
const secretOption = options.getString('secret');
if (secretOption === 'secretcode') {
await interaction.reply('Pong!');
} else {
await interaction.reply('Bong!');
}
}
});
client.login(BOT_TOKEN);
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessages,
],
});
const BOT_TOKEN = 'YOUR_BOT_TOKEN';
const commands = [
{
name: 'ping',
description: 'Ping pong!',
options: [
{
name: 'secret',
description: 'Secret code',
type: 'STRING',
required: true,
},
],
},
];
client.once('ready', async () => {
console.log(`Logged in as ${client.user.tag}!`);
// Register slash commands globally
const application = await client.application.fetch();
await application.commands.set(commands);
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;
const { commandName, options } = interaction;
if (commandName === 'ping') {
const secretOption = options.getString('secret');
if (secretOption === 'secretcode') {
await interaction.reply('Pong!');
} else {
await interaction.reply('Bong!');
}
}
});
client.login(BOT_TOKEN);