How can I make slash commands available in dm's?

I want to use my bot's commands in his dm's but i can only use them in my server. how i can make them avilable in dm's too?
21 Replies
Unknown User
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Serial Designation N
Serial Designation N•16mo ago
discord.js = 14.7.1 node = 18.14.0
chewie 🌈
chewie 🌈•16mo ago
are you using builders?
Serial Designation N
Serial Designation N•16mo ago
slashcommandbuilder
chewie 🌈
chewie 🌈•16mo ago
then you can use builder.setDMPermission(true)
Serial Designation N
Serial Designation N•16mo ago
where?
chewie 🌈
chewie 🌈•16mo ago
on the builder? But you shouldn't have to use that, they are enabled by default The command needs to be global
Serial Designation N
Serial Designation N•16mo ago
how to do this?
d.js docs
d.js docs•16mo ago
guide Creating Your Bot: Command registration - Global commands read more
Serial Designation N
Serial Designation N•16mo ago
i have already something like this. or am i dumb???
chewie 🌈
chewie 🌈•16mo ago
those are guild commands
chewie 🌈
chewie 🌈•16mo ago
also you should use version 10, not 9
Serial Designation N
Serial Designation N•16mo ago
ok now it shows up in dm's.
SSj4 Is Daddymode
SSj4 Is Daddymode•6d ago
So, it looks like whatever website that image was hosted in was banned. Any chance you still remember/have what it was?
chewie 🌈
chewie 🌈•6d ago
It's not banned, it quite simply just doesn't exist anymore. But no. What do you need help with?
SSj4 Is Daddymode
SSj4 Is Daddymode•6d ago
Damn. Well, essentially, having the same issue that OP originally had — my flash commands are not showing up in DMs, and I think I have my builder properly set, and not on guild.
const { Events } = require('discord.js');
const { REST, Routes } = require('discord.js');
require('dotenv').config();
const { CLIENT_ID: clientId, DISCORD_TOKEN: token } = process.env;
const fs = require('node:fs');
const path = require('node:path');

module.exports = {
name: Events.ClientReady,
once: true,
execute(client) {
console.log(`Ready! Logged in as ${client.user.tag}`);

const commands = [];
// Grab all the command folders from the commands directory you created earlier
const foldersPath = path.join(__dirname, '../commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

// Construct and prepare an instance of the REST module
const rest = new REST().setToken(token);

// and deploy your commands globally!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

// The put method is used to fully refresh all global commands with the current set
const data = await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();

},
};
const { Events } = require('discord.js');
const { REST, Routes } = require('discord.js');
require('dotenv').config();
const { CLIENT_ID: clientId, DISCORD_TOKEN: token } = process.env;
const fs = require('node:fs');
const path = require('node:path');

module.exports = {
name: Events.ClientReady,
once: true,
execute(client) {
console.log(`Ready! Logged in as ${client.user.tag}`);

const commands = [];
// Grab all the command folders from the commands directory you created earlier
const foldersPath = path.join(__dirname, '../commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
// Grab all the command files from the commands directory you created earlier
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

// Construct and prepare an instance of the REST module
const rest = new REST().setToken(token);

// and deploy your commands globally!
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

// The put method is used to fully refresh all global commands with the current set
const data = await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
})();

},
};
chewie 🌈
chewie 🌈•6d ago
show your command file then
SSj4 Is Daddymode
SSj4 Is Daddymode•6d ago
// creating a ping.js file in the commands/utility folder for your first command. Inside this file, you're going to define and export two items.
const wait = require('node:timers/promises').setTimeout;
// The data property, which will provide the command definition shown above for registering to Discord.
// The execute method, which will contain the functionality to run from our event handler when the command is used.
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
cooldown: 5, // cooldown of five
category: 'utility', // can be used to place in different directories, for reload.js,
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!')
.setDMPermission(true),
async execute(interaction) {
const botLatency = Date.now() - interaction.createdTimestamp;
await interaction.reply('Pong!'); // You have three seconds to establish the first reply
await interaction.editReply(`Pong again!!!!\nBot latency: ${botLatency}ms`);
},
};

// https://discordjs.guide/creating-your-bot/slash-commands.html#individual-command-files
// creating a ping.js file in the commands/utility folder for your first command. Inside this file, you're going to define and export two items.
const wait = require('node:timers/promises').setTimeout;
// The data property, which will provide the command definition shown above for registering to Discord.
// The execute method, which will contain the functionality to run from our event handler when the command is used.
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
cooldown: 5, // cooldown of five
category: 'utility', // can be used to place in different directories, for reload.js,
data: new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!')
.setDMPermission(true),
async execute(interaction) {
const botLatency = Date.now() - interaction.createdTimestamp;
await interaction.reply('Pong!'); // You have three seconds to establish the first reply
await interaction.editReply(`Pong again!!!!\nBot latency: ${botLatency}ms`);
},
};

// https://discordjs.guide/creating-your-bot/slash-commands.html#individual-command-files
Discord.js version 14.15.2 Node version 18.18.0 Note: console.log(commandFiles) yields the correct array of files, of which that one listed is one of them. Don't suppose you remember how you fixed this, do ya?
chewie 🌈
chewie 🌈•6d ago
Their problem was simply that they registered the command on a guild level, which you supposedly aren't doing
SSj4 Is Daddymode
SSj4 Is Daddymode•6d ago
Damn