#Buttons...

33 messages · Page 1 of 1 (latest)

lilac drum
#

Built buttons into my slash command, they output correctly!.
However once I added the event into interactionCreate event - The command now no longer works.
Event:

onst { Events } = require('discord.js');

module.exports = {
  name: Events.InteractionCreate,
  once: false,
  async execute(interaction) {
    if (!interaction.isChatInputCommand()) return;
    if (!interaction.isButton()) return;

    const command = interaction.client.commands.get(interaction.commandName);

    if (!command) {
      console.error(
        `No command matching ${interaction.commandName} was found.`
      );
      return;
    }

    try {
      await command.execute(interaction);
    } catch (error) {
      console.error(error);
      if (interaction.replied || interaction.deferred) {
        await interaction.followUp({
          content: `There was an error while executing ${interaction.commandName} follow up!`,
          ephemeral: true,
        });
      } else {
        await interaction.reply({
          content: `There was an error while executing ${interaction.commandName} reply!`,
          ephemeral: true,
        });
      }
    }
  },
};

The issue is adding:
if (!interaction.isButton()) return;

There are no errors in the terminal, the bot doesn't crash - Nothing to tell me as to why this stops my slashCommand from working.

Ultimately I want to be able to edit the embed the command outputs with the user who interacted with the button.

iron hawk
#

• 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.

meager laurel
#

You return if it’s not a chat input command

#

So that’s why it doesn’t work

lilac drum
meager laurel
#

Ofc it does

#

You wanna use

#

if(x) {
code
} else if(y) {
code
}

#

Then inside of the block for buttons you wanna check interaction.customId

lilac drum
meager laurel
#

customId is the customId you put into the button builder

#

It’s what separates one button to another button

#

when it’s clicked, the interactionCreate event fires with information.

You then need to make sure that it’s a button, hence interaction.isButton()

Make an if statement which checks for that then execute code inside of the block { }

Check for interaction.customId and then do whatever you want from there

lilac drum
#

Okay, I got that inside the buttonBuilder on the slash command - The guide says to get the button interactions all I have to do is add
if (!interaction.isButton()) return to the InteractionCreate event - Which I have done - But it stops the command outright from working - Saying it didn't respond.

meager laurel
#

Exactly as you return if it’s not a button

#

And if it’s not a slash command

#

You need to use blocks

meager laurel
#

If you don’t know what they are, please use Google and #resources

lilac drum
#

So this:

if (!interaction.isChatInputCommand()) {
      return;
    } else if (!interaction.isButton()) {
      return;
    }

Should be this:

if (!interaction.isChatInputCommand()) {
      return;
    } else if (interaction.isButton()) {
      return;
    }
meager laurel
#

So if it’s not a slash command you wanna return and if it’s a button you wanna return…

#

Read the logic

#

atm you’re doing

#

if(!x) {
return }
if(y) {
return }

#

if(x) {
code
} else if(y) {
code
}

#

You wanna do that

lilac drum
#

Well this is what I am not understanding - And all I'm doing is following the guide.

meager laurel
#

It’s because you don’t have a solid understanding of javascript, which comes under the server rules, #rules 2

lilac drum
#

The GUIDE is literally saying to do

if (!interaction.isChatInputCommand()) return
if (!interaction.isButton()) return
meager laurel
#

Yes, in different events. Which you shouldn’t do anyway it’s showing you how to handle each specific part

It’s because you don’t have a solid understanding of javascript, which comes under the server rules, #rules 2

lilac drum
#

It's the same event - InteractionCreate...

However I presume your saying to move the code that follows

if(!interaction.isChatInputCommand())

Inside of an if/else if/else
To treat each interaction, inside of the interactionCreate event as seperate events?

meager laurel
#

I have given you more then enough information to figure this out

lilac drum