#Your code is fine Just remove this line

1 messages · Page 1 of 1 (latest)

rustic fjord
#

if I remove just this line it says that the interaction is already replied because the command already has been replied to with row.

const row = new ActionRowBuilder().addComponents(
            new SelectMenuBuilder()
              .setCustomId('server_select')
              .setPlaceholder('Select a server')
              .addOptions(SERVER)
              )
        await interaction.reply({components: [row] ,ephemeral: true });
    await interaction.deferReply({ ephemeral: true });
    },
};


client.on('interactionCreate', async interaction => {
    if (!interaction.isSelectMenu()) return;
    if (interaction.customId === 'server_select') {
      await wait(2000);
      const server = interact.values[0];

      await axios
        .post(`${API_BASE_URL}/api/whitelist`, {
          user: target.id,
          userName: target.username,
          server: server,
        })
        .then(res => {
          const embed = new EmbedBuilder()
            .setColor(res.data.color)
            .setTitle('Whitelist | API')
            .setDescription(res.data.message)
            .setTimestamp()
            .setFooter({
              text: 'Bot by: @EnteNico',
            });
           interaction.editReply({
            components: [],
            embeds: [embed],
          });
        });
    }
  });

cobalt karma
#
const row = new ActionRowBuilder().addComponents(
            new SelectMenuBuilder()
              .setCustomId('server_select')
              .setPlaceholder('Select a server')
              .addOptions(SERVER)
              )
    await interaction.deferReply({ ephemeral: true });
    },
};


client.on('interactionCreate', async interaction => {
    if (!interaction.isSelectMenu()) return;
    if (interaction.customId === 'server_select') {
      await wait(2000);
      const server = interact.values[0];

      await axios
        .post(`${API_BASE_URL}/api/whitelist`, {
          user: target.id,
          userName: target.username,
          server: server,
        })
        .then(res => {
          const embed = new EmbedBuilder()
            .setColor(res.data.color)
            .setTitle('Whitelist | API')
            .setDescription(res.data.message)
            .setTimestamp()
            .setFooter({
              text: 'Bot by: @EnteNico',
            });
           interaction.editReply({
            components: [],
            embeds: [embed],
          });
        });
    }
  });``` try that
rustic fjord
cobalt karma
#
await interaction.deferReply({ ephemeral: true });
const row = new ActionRowBuilder().addComponents(
            new SelectMenuBuilder()
              .setCustomId('server_select')
              .setPlaceholder('Select a server')
              .addOptions(SERVER)
              )
await interaction.editReply({ components: [row] });
    },
};


client.on('interactionCreate', async interaction => {
    if (!interaction.isSelectMenu()) return;
    if (interaction.customId === 'server_select') {
      await wait(2000);
      const server = interact.values[0];

      await axios
        .post(`${API_BASE_URL}/api/whitelist`, {
          user: target.id,
          userName: target.username,
          server: server,
        })
        .then(res => {
          const embed = new EmbedBuilder()
            .setColor(res.data.color)
            .setTitle('Whitelist | API')
            .setDescription(res.data.message)
            .setTimestamp()
            .setFooter({
              text: 'Bot by: @EnteNico',
            });
           interaction.editReply({
            components: [],
            embeds: [embed],
          });
        });
    }
  });```
#

Try that?

rustic fjord
#

now the select menu shows up again but the response is missing (interaction dont work because it takes too long)
like the same problem as before :/

cobalt karma
#

So what are you actually trying to achieve? I am just trying to fix random stuff at this point KEKW

rustic fjord
#

jeah i saw this
well its simple

Command with user option
open a select menu
the selct menu returns a value to a api

At the moment it seems to take to loong for the api to make a respone and the edit reply get cancelled

(im also just trying to fix that by a nearly comleted recode because the original dude have messy code that didnt really worked)

cobalt karma
#

So when the user gets the menu (drop down), and they select an option, what are you wanting the bot to do? Remove the menu and replace it with a message?

rustic fjord
#

replace the menu with a embed that shows the error or a success

cobalt karma
#
await interaction.deferReply({ ephemeral: true });
const row = new ActionRowBuilder().addComponents(
            new SelectMenuBuilder()
              .setCustomId('server_select')
              .setPlaceholder('Select a server')
              .addOptions(SERVER)
              )
await interaction.editReply({ components: [row] });
    },
};


client.on('interactionCreate', async interaction => {
    if (!interaction.isSelectMenu()) return;
    if (interaction.customId === 'server_select') {
      await interaction.message.delete()
      await wait(2000);
      const server = interact.values[0];

      await axios
        .post(`${API_BASE_URL}/api/whitelist`, {
          user: target.id,
          userName: target.username,
          server: server,
        })
        .then(res => {
          const embed = new EmbedBuilder()
            .setColor(res.data.color)
            .setTitle('Whitelist | API')
            .setDescription(res.data.message)
            .setTimestamp()
            .setFooter({
              text: 'Bot by: @EnteNico',
            });
           interaction.channel.send({
            components: [],
            embeds: [embed],
          });
        });
    }
  });```

Will something like that do?
#

All I did there was deleted the original message and then sent the embed afterwards.

rustic fjord
#

on my way

#

just failed
also no error

rustic fjord
cobalt karma
#

From the deferreply

rustic fjord
#

same issue but the dropdown is now visible for everyone

cobalt karma
#

When is the error occuring? the second you use the slash command?

rustic fjord
#

i use the slash command
dropdown show up
choose option from the dropdown
interaction failed

cobalt karma
#

No errors in console?

rustic fjord
#

none just starting (dont added start log /message because im lazy)

cobalt karma
#

Ok so add a log under if (interaction.customId === 'server_select') { and see if it get's into that part of your code

cobalt karma
# rustic fjord it dont get in

Change this part:

client.on('interactionCreate', async interaction => {
    if (!interaction.isSelectMenu()) return;
    if (interaction.customId === 'server_select') {
      console.log(`I'm here!`)
      await interaction.message.delete()
      await wait(2000);
      const server = interact.values[0];

      await axios
        .post(`${API_BASE_URL}/api/whitelist`, {
          user: target.id,
          userName: target.username,
          server: server,
        })
        .then(res => {
          const embed = new EmbedBuilder()
            .setColor(res.data.color)
            .setTitle('Whitelist | API')
            .setDescription(res.data.message)
            .setTimestamp()
            .setFooter({
              text: 'Bot by: @EnteNico',
            });
           interaction.channel.send({
            components: [],
            embeds: [embed],
          });
        });
    }
  });```
rustic fjord
#

same as before (i add the console log there too)

cobalt karma
#

Does it log anything though?

#

The log will tell you if it's getting to that part of the program

#

So does it say I'm here! in your console

rustic fjord
cobalt karma
#

I can't understand why it won't get to the log I added...

#

hmmm

rustic fjord
#

this is the reason why im ehre
i dont understand it too
but i think i go to sleep now and try again tomorrow
nealy 4am now

cobalt karma
#

Yeah do that, have a good one 👍

rustic fjord
cobalt karma
cobalt karma
# rustic fjord should be in the index.js

Yeah so you need to add it in that file there so instead of having the if(!interaction.IsChatInputCommand()) return line, you can make it an if/else chain so for example:

if(interaction.IsChatInputCommand()){
  //do chat input things
} else if(interaction.IsSelectMenu()) {
  //do those things here
}```
#

See what I am saying?

rustic fjord
#

yes
but im not sure what you mean with
//do chat input things

#
client.on(Events.InteractionCreate, async interaction => {
  if(interaction.IsChatInputCommand()){
    return
    
  } else if(interaction.IsSelectMenu()) {
    if (interaction.customId === 'server_select') {
      console.log(`I'm here!`)

because just like this nothing changed

or do you mean in the index.js?

cobalt karma
#

So for example:

if(interaction.IsChatInputCommand()){
  //all the stuff above that is already in the event
} else if(interaction.IsSelectMenu()) {
  //the things you are trying to do now
  if(interaction.customId === 'server_select){
  }
}```
#

I am not writing it all out that would take a while KEKW

rustic fjord
#

wait im confused are we now in the command or in the index waitWhat

cobalt karma
#

So you have 2 places you have client.on('interactionCreate', right?

#

One is in index.js

#

the other is in a command file

rustic fjord
#

yes

cobalt karma
#

What I am saying,is move it all into the index.js one

#

You don't need 2

#

It's global, so you only need 1 of them.

#

Even better if you have an event handler you could have it in a seperate file.

rustic fjord
#

so i shoould move this stuff to the index or just remove the ```js

client.on(Events.InteractionCreate, async interaction => {
if(interaction.IsChatInputCommand()){
return

} else if(interaction.IsSelectMenu()) { ```

cobalt karma
#

Exactly!

#

You are getting it

#

All needs to be in the index.js file

rustic fjord
#

not 100% just giv e me tha last % XD
i just try both otions 🙂

cobalt karma
#

You have it I think? have you tried it now?

rustic fjord
#

im on my way like im a bit confused if i just remove this stuff


client.on(Events.InteractionCreate, async interaction => {
 if(interaction.IsChatInputCommand()){
   return
   
 } else if(interaction.IsSelectMenu()) { ```

Or if i need to move everything to index.js

but i get the point ![blobsweats](https://cdn.discordapp.com/emojis/358336932343840769.webp?size=128 "blobsweats")
cobalt karma
#

Only thing you need to do is in the ```js
if(interaction.IsChatInputCommand()){

}```

You need to add the stuff that was in there before like the const command = stuff. That was your command handling code.

#

All you are doing is merging the stuff from the 2 into 1 event listener

rustic fjord
#

getting really brainafk with this (i need to translate it and use it in my brain get really difficult to understnad hot to move everything like you tried to erxplain there because its not clear for me which files you add or edit stuff in could be simply a language barrier just give me a few min)

#

brain working really hard right now XD

#

not sure if its not already smoking or in flames

cobalt karma
#

Your not removing any files

#

Basically, you where you are creating the select menu with the command, you don't need the interactionCreate event in there.

#

Move it out, into your one that is in index.js

rustic fjord
#

jeah thats clear i need to edit the index.js to contain the event listener

#

jeah ok

cobalt karma
#

Why I am saying this:

if(interaction.IsChatInputCommand()){
  //all the stuff above that is already in the event
} else if(interaction.IsSelectMenu()) {
  //the things you are trying to do now
  if(interaction.customId === 'server_select){
  }
}```
is because everything that was in your index.js before you made the changes, needs to go inside the `IsChatInputCommand()` if statement. Like so:
```js
if(interaction.IsChatInputCommand()){
  const command = client.commands.get() //etc etc
}``` and inside the `IsSelectMenu()` elseif statement you need the stuff you are trying to do now with the `customId's` and all that.
rustic fjord
cobalt karma
#

Paste that part of the code here

rustic fjord
#

here?

cobalt karma
#

yeah

#

I can fix it for you

#

then you can have a read and understand

rustic fjord
#

ok waht do yiu need ?
index and command file or just the indey file?

cobalt karma
#

Just everything that is inside the client.on('interactionCreate'

rustic fjord
#

client.on('interactionCreate', async interaction =>
{
    if (!interaction.isChatInputCommand()) return;

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

    if (!command) return;

    if(interaction.IsChatInputCommand()){
        return
        
      } else if(interaction.IsSelectMenu()) { 
        if (interaction.customId === 'server_select') {
            console.log(`I'm here!`)
            await interaction.message.delete()
            await wait(2000);
            const server = interact.values[0];
        
            await axios
              .post(`${API_BASE_URL}/api/whitelist`, {
                user: target.id,
                userName: target.username,
                server: server,
              })
              .then(res => {
                const embed = new EmbedBuilder()
                  .setColor(res.data.color)
                  .setTitle('Whitelist | API')
                  .setDescription(res.data.message)
                  .setTimestamp()
                  .setFooter({
                    text: 'Bot by: @EnteNico',
                  });
                interaction.channel.send({
                  components: [],
                  embeds: [embed],
                });
              });
          }
      }
    try
    {
        await command.execute(interaction);
    } catch (error)
    {
        console.error(error);
        await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
    }
});
cobalt karma
#
client.on('interactionCreate', async interaction =>
{
    if(interaction.IsChatInputCommand()){
        const command = client.commands.get(interaction.commandName);
        if (!command) return;

        
        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.IsSelectMenu()) { 
        if (interaction.customId === 'server_select') {
            console.log(`I'm here!`)
            await interaction.message.delete()
            await wait(2000);
            const server = interact.values[0];
        
            await axios
              .post(`${API_BASE_URL}/api/whitelist`, {
                user: target.id,
                userName: target.username,
                server: server,
              })
              .then(res => {
                const embed = new EmbedBuilder()
                  .setColor(res.data.color)
                  .setTitle('Whitelist | API')
                  .setDescription(res.data.message)
                  .setTimestamp()
                  .setFooter({
                    text: 'Bot by: @EnteNico',
                  });
                interaction.channel.send({
                  components: [],
                  embeds: [embed],
                });
              });
          }
      }
});```
#

That should work

#

Because you are saying:

Right, if it's a command then do the command stuff, else if it's a select menu interaction do this stuff here.

rustic fjord
#

poggies
jeah make sence

cobalt karma
#

Make sure you removed the interactionCreate from your command file where the 2nd one was

rustic fjord
#

uhm

cobalt karma
#

Lowercase I at the beginning of isChatInputCommand sorry that was my fault

rustic fjord
#

jeah all good
didnt saw that too first

cobalt karma
#

What is target though?

rustic fjord
#

the user that is in the user option of the commandhttps://Chaosfelix.monarchuploader.de/Dh6FXgIhLbsB/Code_gQ1EObFK5l

Upload von Felix
Hochgeladenes Bild/Datei
cobalt karma
#

Bare with me

#

Your going to have to re-work your code in order to use target.

#

You'll need to use a messageComponent collector.

#

It's the last bit of information.

#

It'll be hard work but it'll be worth it in the end.

#

You can use that message collector inside of the command file you have for the select menu

rustic fjord
#

well i looked over google could be much more simple by a module export.
going to try that first maiby it work if not i look in the message Component

cobalt karma
#

Best of luck! I hope it works for you!

rustic fjord
#

jeah just trying to fix some stuff to get slowly more into js what happens i fall into the deep
So a really big thank to you for helping me with the most annoying problem im going to look throught the docs now

cobalt karma
rustic fjord