#Discord slash command

3 messages · Page 1 of 1 (latest)

silver nexus
#

Hello, I made a slash command - everything works well on the server, and I installed the user app, however I do not see the bot command registered in DMs, however it is for any other server, is there a setting to enable?

fickle canopyBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by OP
silver nexus
#

I installed the user app

const { Client, GatewayIntentBits, REST, Routes } = require('discord.js');
const mongoose = require('mongoose');
const dotenv = require('dotenv');

dotenv.config();

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

const commands = [
    {
        name: 'hello',
        description: 'Replies with Hello, World!',
    },
];

const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);

async function connectDatabase() {
    try {
        await mongoose.connect(process.env.MONGODB_URI, {
            useNewUrlParser: true,
            useUnifiedTopology: true,
        });
        console.log('Connected to MongoDB');
    } catch (error) {
        console.error('Error connecting to MongoDB:', error);
    }
}

client.once('ready', async () => {
    try {
        await rest.put(
            Routes.applicationCommands(process.env.CLIENT_ID),
            { body: commands }
        );
        console.log('Slash commands registered successfully');
    } catch (error) {
        console.error(error);
    }
    console.log('Bot is ready');
    await connectDatabase();
});

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

    if (interaction.commandName === 'hello') {
        await interaction.reply('Hello, World!');
    }
});

client.login(process.env.TOKEN);