Use an application bot slash commands in dms

So basically I can use it anywhere but in dms for some reason
13 Replies
d.js toolkit
d.js toolkit4mo 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 staff
GGGhaith
GGGhaith4mo ago
Hello! 👋 This works in both DMs and servers!
ggghaith
ggghaithOP4mo ago
I tried to use ai for help But didnt work And made my code spagetti So dont wanna send it here I just want to register them to dms I fixed a bit of the ai code
const { Client, GatewayIntentBits, SlashCommandBuilder } = require('discord.js');
const { token } = require('./config.json'); // Store your bot token in config.json

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

// Event listener for when the bot is ready
client.once('ready', () => {
console.log('Bot is online!');
// Register slash commands when the bot is ready
client.application.commands.set([
new SlashCommandBuilder().setName('hello').setDescription('Say hello to the bot!'),
]).then(() => {
console.log('Slash commands registered');
}).catch(console.error);
});

// Event listener for interactions (slash commands)
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;

const { commandName } = interaction;

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

// Log in to Discord with your app's token
client.login(token);
const { Client, GatewayIntentBits, SlashCommandBuilder } = require('discord.js');
const { token } = require('./config.json'); // Store your bot token in config.json

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

// Event listener for when the bot is ready
client.once('ready', () => {
console.log('Bot is online!');
// Register slash commands when the bot is ready
client.application.commands.set([
new SlashCommandBuilder().setName('hello').setDescription('Say hello to the bot!'),
]).then(() => {
console.log('Slash commands registered');
}).catch(console.error);
});

// Event listener for interactions (slash commands)
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return;

const { commandName } = interaction;

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

// Log in to Discord with your app's token
client.login(token);
d.js docs
d.js docs4mo ago
:method: SlashCommandBuilder#setIntegrationTypes() @1.9.0 Sets the integration types of this command. :method: SlashCommandBuilder#setContexts() @1.9.0 Sets the contexts of this command.
ggghaith
ggghaithOP4mo ago
So I install another package @Qjuh to what Should I set it Then how What should I edit To what I wanted to be available in dma The docs dont show to what I can set it
d.js docs
d.js docs4mo ago
:dtypes: v10: ApplicationIntegrationType read more
ggghaith
ggghaithOP4mo ago
@Qjuh it is already installable Look
d.js docs
d.js docs4mo ago
:dtypes: v10: InteractionContextType read more
ggghaith
ggghaithOP4mo ago
Ok so I just edit the context type @Qjuh i add it to new SlashCommandBuilder right Oh sorry but I add it to the SlashCommandBuilder Right Thx @Qjuh it only eorked in dms Now it doesnt work anywhere else Just in dms Can you do it Iy didnt work for me
Amgelo
Amgelo4mo ago
it accepts many contexts, not just one you passed only one, so it'll only work in that one pass every context you want it to work on
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View
Amgelo
Amgelo4mo ago
quite literally just pass more contexts to the method the method accepts an unlimited amount of arguments yes, but don't use raw values use the enum it's the same internally but it's more readable not really
Unknown User
Unknown User4mo ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?