interactionCreate slash commands not firing

const { InteractionType } = require("discord.js");module.exports = { name: "interactionCreate", on: true, async execute(interaction) { if (interaction.type === InteractionType.ApplicationCommand) { const command = interaction.client.commands.get(interaction.commandName); if (!command) return; console.log("past"); try { await command.execute(interaction); } catch (error) { console.error(error); await interaction.reply({ content: "There was an error while executing this command!", ephemeral: true, }); } } else if (interaction.type === InteractionType.ModalSubmit) { if (interaction.customId === "modal") { await interaction.reply({ content: "Subbmited", ephemeral: true }); } } },};
const { InteractionType } = require("discord.js");module.exports = { name: "interactionCreate", on: true, async execute(interaction) { if (interaction.type === InteractionType.ApplicationCommand) { const command = interaction.client.commands.get(interaction.commandName); if (!command) return; console.log("past"); try { await command.execute(interaction); } catch (error) { console.error(error); await interaction.reply({ content: "There was an error while executing this command!", ephemeral: true, }); } } else if (interaction.type === InteractionType.ModalSubmit) { if (interaction.customId === "modal") { await interaction.reply({ content: "Subbmited", ephemeral: true }); } } },};
2 Replies
d.js docs
d.js docs2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
PAdventures
PAdventures2y ago
const { InteractionType } = require('discord.js');
module.exports = {
name: 'interactionCreate',
on: true,
async execute(interaction){
if (interaction.type === InteractionType.ApplicationCommand){
const command = interaction.client.commands.get(interaction.commandName); if (!command) return;
console.log('past')
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true }); }
} else if (interaction.type === InteractionType.ModalSubmit){
if (interaction.customId === 'modal'){ await interaction.reply({ content: 'Subbmited', ephemeral: true })
} } }}
const { InteractionType } = require('discord.js');
module.exports = {
name: 'interactionCreate',
on: true,
async execute(interaction){
if (interaction.type === InteractionType.ApplicationCommand){
const command = interaction.client.commands.get(interaction.commandName); if (!command) return;
console.log('past')
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true }); }
} else if (interaction.type === InteractionType.ModalSubmit){
if (interaction.customId === 'modal'){ await interaction.reply({ content: 'Subbmited', ephemeral: true })
} } }}
console.log(command) -> undefined past not in console ? what does you mean? did i not setup the collection correctly
client.commands = new Collection();
const commands = [];
const commandsPath = path.join(__dirname, 'Commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath); commands.push(command.data.toJSON());}
client.commands = new Collection();
const commands = [];
const commandsPath = path.join(__dirname, 'Commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath); commands.push(command.data.toJSON());}
const rest = new REST({ version: '10' }).setToken(process.env.HGD_TOKEN);
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
const data = await rest.put( Routes.applicationCommands(process.env.HGD_CLIENT_ID), { body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}})();
const rest = new REST({ version: '10' }).setToken(process.env.HGD_TOKEN);
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
const data = await rest.put( Routes.applicationCommands(process.env.HGD_CLIENT_ID), { body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}})();
? got it working