Energy Drink Addict
Energy Drink Addict
DIAdiscord.js - Imagine an app
Created by Energy Drink Addict on 5/27/2024 in #djs-questions
Global Commands Not Showing In DM
That was it, thank you.
4 replies
DIAdiscord.js - Imagine an app
Created by Serial Designation N on 2/17/2023 in #djs-questions
How can I make slash commands available in dm's?
Damn
26 replies
DIAdiscord.js - Imagine an app
Created by Serial Designation N on 2/17/2023 in #djs-questions
How can I make slash commands available in dm's?
Don't suppose you remember how you fixed this, do ya?
26 replies
DIAdiscord.js - Imagine an app
Created by Serial Designation N on 2/17/2023 in #djs-questions
How can I make slash commands available in dm's?
Note: console.log(commandFiles) yields the correct array of files, of which that one listed is one of them.
26 replies
DIAdiscord.js - Imagine an app
Created by Serial Designation N on 2/17/2023 in #djs-questions
How can I make slash commands available in dm's?
// 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
26 replies
DIAdiscord.js - Imagine an app
Created by Serial Designation N on 2/17/2023 in #djs-questions
How can I make slash commands available in dm's?
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);
}
})();

},
};
26 replies
DIAdiscord.js - Imagine an app
Created by Serial Designation N on 2/17/2023 in #djs-questions
How can I make slash commands available in dm's?
So, it looks like whatever website that image was hosted in was banned. Any chance you still remember/have what it was?
26 replies