#can u show ur code actually

1 messages · Page 1 of 1 (latest)

velvet rampart
#

here you go

frank meadow
#

one sec

velvet rampart
karmic ingot
#

interaction.message

#

U can use

frank meadow
#

attach const message to your interaction.reply, then add fetchReply: true in the reply options

velvet rampart
#

const message = await interaction.reply({ content: "test", fetchReply: true, ephemeral: true, components: [row] })

frank meadow
#

using interaction.message also works

velvet rampart
#

so like that?

frank meadow
#

yes

velvet rampart
#

OK LET ME TRY

#

caps

velvet rampart
# frank meadow yes

Ok so it worked, I have a few more questions if you don't mind, first off, do I need to have time: 15000 for the collector or will it jsut end automaticly on the collector.on('end'...)...

frank meadow
#

having the time means it will end after 15 seconds in your case. without a time, the collector never ends unless you call collector.stop()

velvet rampart
frank meadow
#

well that event gets called whenever the collector ends regardless if there is a time set or not. collector.stop() could go inside the collect event

velvet rampart
#

sorry for ping

#

forgot to remove it

frank meadow
#

no worries, but you can use that event to run any specific code when the collector ends

#

up to you though

#

like you can send a reply in the end event saying 'collector ended' or something like that

velvet rampart
#

OH

#

Ok

#

One more question, sorry

frank meadow
#

ask as many as you want

velvet rampart
#

if(i.customId == 'blacklist') {

firstBtn.setDisabled(true)
secondBtn.setDisabled(true)

}

#

I have this right, it doesn't disble the buttons,

#

am i better off just making a new ActionRow?

#

And setting those to disabled?

frank meadow
#

you dont exactly declare these

velvet rampart
#

So would I just add const firstBtn = under the .addComponents(

frank meadow
#

you could. or you can define an array of both buttons in lets say an array like const buttons = [new ButtonBuilder(), ...] and then .addComponents(buttons) on the action row. then you can call buttons[0] and buttons[1] and .setDisabled() that way

velvet rampart
frank meadow
#

thats fine lol

velvet rampart
frank meadow
#

buttons is an array, hence the buttons[0] since thats the first thing in the array

velvet rampart
#

Oh right its a array

#
 const buttons = [new ButtonBuilder(), 
        
            firstBtn = new ButtonBuilder()
        .setCustomId('blacklist')
        .setLabel('Yes')
        .setStyle(ButtonStyle.Success),
        
        secondBtn = new ButtonBuilder()
        .setCustomId('cancel')
        .setLabel('No')
        .setStyle(ButtonStyle.Primary)
        ]
        let row = new ActionRowBuilder()
        .addComponents(buttons)
#

would it be like that

#

wait nvm

#

hold on

#

i dont need the seconBtn

#

and first

#

or wait maybe i do

#
const buttons = [new ButtonBuilder()
        
        .setCustomId('blacklist')
        .setLabel('Yes')
        .setStyle(ButtonStyle.Success)
        
        .setCustomId('cancel')
        .setLabel('No')
        .setStyle(ButtonStyle.Primary)
        ]
        let row = new ActionRowBuilder()
        .addComponents(buttons)
``` like this?
frank meadow
#

yes thats good

#

wait

#

2 ButtonBuilders

velvet rampart
#

or wait i think i forgot some bracets

frank meadow
#

with a comma after the first one

velvet rampart
#

ye

#

Sorry im just trying to figure it out lol

frank meadow
#

you're fine

velvet rampart
#

Do you mind if I ask why a comma is needed after the first one, cuz when I did that it gives me a sytax error.

frank meadow
#

that's how you separate the 2 values in the array

velvet rampart
#

Oh

#
const buttons = [new ButtonBuilder(),
        .setCustomId('blacklist')
        .setLabel('Yes')
        .setStyle(ButtonStyle.Success),
        
        new ButtonBuilder()
        .setCustomId('cancel')
        .setLabel('No')
        .setStyle(ButtonStyle.Primary)
        ]
        let row = new ActionRowBuilder()
        .addComponents(buttons)
frank meadow
#

yes

#

buttons[0] is your blacklist button
buttons[1] is your cancel button

velvet rampart
#

Ok, let me give a shot

#

It said couldn't find name button. Did you mean buttons?

frank meadow
#

yes

#

whoops i forgot buttons lol my bad

velvet rampart
frank meadow
#

remove the comma from ButtonBuilder

#

the comma is needed after each index to separate each value in the array

velvet rampart
#

it isnt disabling buttons

frank meadow
#

can you show ur updated code

velvet rampart
frank meadow
#

you know actually

#

you should edit the buttons in the editReply

velvet rampart
#

What do you mean?

frank meadow
#

like this

#
interaction.editReply({
                    content: 'ok',
                    components: [
                        buttons[0].setDisabled(true),
                        buttons[1].setDisabled(true)
                    ]
                })
#

dont use this

#

one sec

velvet rampart
frank meadow
#
const r = new ActionRowBuilder().addComponents(
                    buttons[0].setDisabled(true),
                    buttons[1].setDisabled(true)
                )
                interaction.editReply({
                    content: 'ok',
                    components: [r]
                })
#

sorry edited because i use ts

#

see if this works for you

velvet rampart
#

Ok

#

that shoul dbe going in the if statement right?

frank meadow
#

yea

velvet rampart
#

Ok so it worked.

frank meadow
#

great!

velvet rampart
#

but it just always says interaction failed

#

even tho it worked

#

Does that always happen?

frank meadow
#

uh no, but try awaiting the editReply

velvet rampart
#

k

#

says its not allowed

frank meadow
#

lol what..

#

wdym

velvet rampart
frank meadow
#

oh just make the collect function async

#

async i

velvet rampart
frank meadow
#

do the buttons still disable?

velvet rampart
#

yes

frank meadow
#

i wonder if the interaction is taking more than 3 seconds to give a response

#

do me a favor, try changing interaction.editReply to i.update but with the same data

velvet rampart
#

the button gives the 3 dots thing until it gives that

frank meadow
#

could be taking like 3.1 seconds to respond lol

velvet rampart
#

wow

#

that fixed it

#

sweet!

frank meadow
#

oh nice

velvet rampart
#

I have one last question haha

frank meadow
#

ask away

velvet rampart
#

and then ill be done probs

#

If I only wanted to allow the user who started to interaction to be able to use the buttons how would I do that?

frank meadow
#

you would need to use a filter in the collector

velvet rampart
#

Ok let me try to do it and then ill send u what i got!

frank meadow
#

okay

velvet rampart
#

const filter = i => {
if (i.user.id === interaction.user.id) {
i.reply(${i.user.id} clicked on the ${i.customId} button.);
} else {
i.reply({ content: These buttons aren't for you!, ephemeral: true });
};

#

Like that?

frank meadow
#

yea, but you are missing if before the (...user.id ==)`

velvet rampart
#

so like that?

frank meadow
#

looks alright

velvet rampart
#

Ok and im putting that inside the collector right?

frank meadow
#

yea just call filter in the collector options

velvet rampart
#

What do you mean in the collector options?

frank meadow
#

in here

velvet rampart
#

Oh, alright.

#

filter,

#

oops

#

it says its expecting a comma both times

frank meadow
#

you can remove the template literal since a user id is a string

#

template literals go inside backticks `${}`

velvet rampart
#

oh thats right, sorry im like 6 months into coding so im still figuring this stuff out

frank meadow
#

dont worry about it

scenic aspenBOT
#

mdn Template literals (Template strings)
Template literals are literals delimited with backtick (`) characters, allowing for multi-line strings, string interpolation with embedded expressions, and special constructs called tagged templates.

velvet rampart
#

Ok, it is now saying where we put the await i.update isnt valid anymore

#

I can give you error if you want

#

await i.update({
^^^^^

SyntaxError: await is only valid in async functions and the top level bodies of modules

frank meadow
#

async function

#

async i

velvet rampart
#

oh for the filter?

frank meadow
#

can u show updated code

velvet rampart
#
const { SlashCommandBuilder } = require('discord.js');
const { MessageActionRow, MessageButton, ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, ComponentType } = require('discord.js');

module.exports = {

    data: new SlashCommandBuilder()
        .setName('button')
        .setDescription('button'),
    async execute(interaction) {
        
        const buttons = [new ButtonBuilder()
        .setCustomId('blacklist')
        .setLabel('Yes')
        .setStyle(ButtonStyle.Success),
        
        new ButtonBuilder()
        .setCustomId('cancel')
        .setLabel('No')
        .setStyle(ButtonStyle.Primary)
        ]
        let row = new ActionRowBuilder()
        .addComponents(buttons)

const message = await interaction.reply({ content: "test", fetchReply: true, ephemeral: true, components: [row] })
const collector = message.createMessageComponentCollector({ componentType: ComponentType.Button, filter });

collector.on('collect', async i => { 
    
    const filter = async i => {
        if (i.user.id === interaction.user.id) {
             i.followUp(`hi`);
         } else {
             i.reply({ content: `These buttons aren't for you!`, ephemeral: true });
         }; 
     
  if(i.customId == 'blacklist') {
   
    const r = new ActionRowBuilder().addComponents(
        buttons[0].setDisabled(true),
        buttons[1].setDisabled(true)
    )
    await i.update({
        content: 'ok',
        components: [r]
    })
  }

 if(i.customId == 'cancel') {

    interaction.editReply("Canceled")
 }
 collector.stop()
});
      collector.on('end', collected => {
    console.log(`Collected ${collected.size} interactions.`);
});
}};
frank meadow
#

put the filter before you make the collector

velvet rampart
#

👍

frank meadow
#

put it right above const collector

velvet rampart
#

k

frank meadow
#

also change the i.followUp to a reply

velvet rampart
#

Okay

velvet rampart
frank meadow
#

use reply instead of followUp

velvet rampart
#

Ok

#

the buttons dont respond npw

#

just says failed

#

@frank meadow

frank meadow
#

ah i know

#

change the interaction.reply to i.reply

velvet rampart
#

still doesnt respond

#

@frank meadow

#

and also, should all the filter code be above all that, or should i be putting a } somewhere lower?

frank meadow
#

wait, the code u provided has some syntax errors

#

have you fixed those?

velvet rampart
#

let me c

#

vsc doesnt show anything

frank meadow
#

wait

#

no u didnt

#

hold on

velvet rampart
#

this is the code i have right now

frank meadow
#

pastebin is just weird nvm

velvet rampart
#

ok

frank meadow
#

you're also better off doing !== instead of !i.user.id, which basically means if the i.user.id isnt present or false

velvet rampart
#

Ok.

#

so like that

#

but thats still not equal ovs

frank meadow
#

i.user.id !== interaction.user.id means if the i.user.id is not equal to the interaction.user.id

velvet rampart
#

like that right?

frank meadow
#

see if that works

velvet rampart
#

nope

frank meadow
#

this is from the djs guide which you should use

if (i.user.id === interaction.user.id) {
        i.reply(`${i.user.id} clicked on the ${i.customId} button.`);
    } else {
        i.reply({ content: `These buttons aren't for you!`, ephemeral: true });
    }
velvet rampart
#

OK

#
const filter = async i => {
    if (i.user.id === interaction.user.id) {
        i.reply(`${i.user.id} clicked on the ${i.customId} button.`);
    } else {
        i.reply({ content: `These buttons aren't for you!`, ephemeral: true });
    }}
scenic aspenBOT
#

guide Popular Topics: Interaction collectors - Basic message component collector
read more

frank meadow
#

check the guide on this it will help explain it better than i am

velvet rampart
#

its workin i think now

#

@frank meadow now if i click the button it says I click it but doesnt run the code for the button statements

#

it runs the filter code but not anything after dat

frank meadow
velvet rampart
#

Ok

#

here is code, it says Interaction has already been acknowledged.

frank meadow
#

ah okay so try changing i.update to interaction.editReply. if that doesnt work, then try i.editReply

#

this wont work btw. interaction.i isnt a thing

velvet rampart
#

oh i didnt even mean to put untercation ther ok thx

#

Okay!

#

that fixed it

#

Thank you so much for all the help you gbave

#

gave me

frank meadow
#

lovely

velvet rampart
#

really appricate it

#

thanks so much

frank meadow
#

im glad i could help

velvet rampart
#

Have a good one!

frank meadow
#

thanks you as well

velvet rampart
#

const channel = client.channels.cache.get('992640169712820275');
await channel.send({ embeds: [msgEmbed] });

#

TypeError: Cannot read properties of undefined (reading 'send')

#

@frank meadow why would that be, it worked fine right until i put it inside the if statement for the button

frank meadow
#

Id is prolly wrong

velvet rampart
#

ye i realized that just now haha

velvet rampart
frank meadow
#

U don’t use r in anything

#

U can probably do i.update with passing r as the components. I don’t believe that would cause an err

velvet rampart
#

@frank meadow hey are you able t help me with something else?

frank meadow
#

I’m so sorry, I’ve been so busy lately that I haven’t had a lot of time to help. I hope someone else is able to in the mean time !