Discord slash command

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?
2 Replies
d.js toolkit
d.js toolkit3mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - 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
Sabry
SabryOP3mo ago
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);
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);
it shows the command in every servers, so the user app worked, but not in DMs, am I missing something?

Did you find this page helpful?