#interaction not working

15 messages · Page 1 of 1 (latest)

forest joltBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • 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
chrome flicker
#

can you share your entire code? also there's no "data" property in interactions, you're looking for commandName

radiant grottoBOT
unreal sentinel
# chrome flicker can you share your entire code? also there's no "data" property in interactions,...

for (const file of eventFiles) {
    const event = require(path.join(eventsDir, file));
    if (event.once) {
        console.log(event.name)
        bot.once(event.name, (...args) => event.execute(...args));
    } else {
        console.log(event.name)
        bot.on(event.name, (...args) => event.execute(...args));
    }
}

bot.commands = new Map();

const slashCommandFiles = fs.readdirSync(slashCommandsDir).filter(file => file.endsWith('.js'));
for (const file of slashCommandFiles) {
    const command = require(path.join(slashCommandsDir, file));
    bot.commands.set(command.name, command);
}

bot.on('interactionCreate', async (interaction) => {
    console.log(interaction);
    if (!interaction.isCommand()) return;

    const command = bot.commands.get(interaction.data.name);

    if (!command) return;
    
    try {
        await command.execute(interaction);
    } catch (error) {
        console.log(error);
        await interaction.reply({
            content: 'There was an error while executing this command!', 
            ephemeral: true
        });
    }
});

The paths are stated correctly

#

const eventsDir = path.resolve(__dirname, 'events');
const slashCommandsDir = path.resolve(__dirname, 'commands/testing');
#

My on ready file works

harsh nacelle
#

And what did you do that you think should cause an interaction?

unreal sentinel
#

A slash command

harsh nacelle
#

Of that bot? And the bot is (and stays) online while doing so?

unreal sentinel
#

?

#

I’m exporting my bot in my index file and getting it inside a another file but anything I do with the bot in it it says it’s undefined

harsh nacelle
#

Yeah, you shouldn’t do that. That causes circular dependencies causing your issue. Instead pass the bot (Client) when calling that other file.

#

Or just use the .client property virtually any djs payload has

radiant grottoBOT
#

Suggestion for @sterile juniper:
discord Discord Voice
read more

harsh nacelle
#

@still aspen how about not pinging a mod with docs in a thread you didn’t even join yourself?