#Hello sorry im new to this but did i do this right

1 messages · Page 1 of 1 (latest)

fervent grove
const { Client, Intents } = require('discord.js');
require('dotenv').config();

const client = new Client({
    intents: [
        Intents.FLAGS.GUILDS,           // Allows the bot to interact with guilds (servers)
        Intents.FLAGS.GUILD_MESSAGES   
    ]
});

client.commands = new Map();

const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    client.commands.set(command.name, command);
}

client.once('ready', () => {
    console.log('Bot is ready!');

    client.user.setPresence({
        activities: [{ name: 'd', type: 'PLAYING' }],
        status: 'online',
    });

   
    const guildId = '1254264050658054204'; 

    client.guilds.cache.get(guildId)?.commands.set(Array.from(client.commands.values())).then(() => {
        console.log('Slash commands registered!');
    }).catch(console.error);
});

client.on('interactionCreate', async interaction => {
    if (!interaction.isCommand()) return;

    const { commandName } = interaction;

    if (!client.commands.has(commandName)) return;

    try {
        await client.commands.get(commandName).execute(interaction);
    } catch (error) {
        console.error(error);
        await interaction.reply({ content: 'There was an error executing this command.', ephemeral: true });
    }
});

client.login(process.env.DISCORD_TOKEN);