#can u show ur code actually
1 messages · Page 1 of 1 (latest)
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
here you go
one sec
Ok, thanks so much for helping me
attach const message to your interaction.reply, then add fetchReply: true in the reply options
const message = await interaction.reply({ content: "test", fetchReply: true, ephemeral: true, components: [row] })
using interaction.message also works
so like that?
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'...)...
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()
Ok so I could remove collector.on('end', collected => {
console.log(Collected ${collected.size} interactions.); and just replace it with collector.stop()?
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
Ok, do i even need the collector.on('end)...
sorry for ping
forgot to remove it
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
ask as many as you want
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?
you dont exactly declare these
So would I just add const firstBtn = under the .addComponents(
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
Okay, i'll give a shot, thanks so much. I will most likely have another question haha.
thats fine lol
Sorry one question, how would I call the buttons? Do I have to do replace that 0 with the CustomID?
buttons is an array, hence the buttons[0] since thats the first thing in the array
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?
or wait i think i forgot some bracets
with a comma after the first one
you're fine
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.
that's how you separate the 2 values in the array
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)
remove the comma from ButtonBuilder
the comma is needed after each index to separate each value in the array
it isnt disabling buttons
can you show ur updated code
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
What do you mean?
like this
interaction.editReply({
content: 'ok',
components: [
buttons[0].setDisabled(true),
buttons[1].setDisabled(true)
]
})
dont use this
one sec
👍
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
yea
Ok so it worked.
great!
but it just always says interaction failed
even tho it worked
Does that always happen?
uh no, but try awaiting the editReply
Ok it still says interaction failed
do the buttons still disable?
yes
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
the button gives the 3 dots thing until it gives that
could be taking like 3.1 seconds to respond lol
oh nice
I have one last question haha
ask away
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?
you would need to use a filter in the collector
Ok let me try to do it and then ill send u what i got!
okay
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?
yea, but you are missing if before the (...user.id ==)`
so like that?
looks alright
Ok and im putting that inside the collector right?
yea just call filter in the collector options
What do you mean in the collector options?
in here
you can remove the template literal since a user id is a string
template literals go inside backticks `${}`
oh thats right, sorry im like 6 months into coding so im still figuring this stuff out
dont worry about it
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.
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
oh for the filter?
can u show updated code
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.`);
});
}};
put the filter before you make the collector
👍
put it right above const collector
k
also change the i.followUp to a reply
Okay
i keep getting an error saying this interaction has already been replied to
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
use reply instead of followUp
Ok
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
the buttons dont respond npw
just says failed
@frank meadow
still doesnt respond
@frank meadow
and also, should all the filter code be above all that, or should i be putting a } somewhere lower?
you added an extra }
wait
no u didnt
hold on
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
this is the code i have right now
pastebin is just weird nvm
ok
you should be checking if the i.user.id is not equal to the interaction.user.id
you're also better off doing !== instead of !i.user.id, which basically means if the i.user.id isnt present or false
i.user.id !== interaction.user.id means if the i.user.id is not equal to the interaction.user.id
if (i.user.id !== interaction.user.id) {
interaction.reply({ content: These buttons aren't for you!, ephemeral: true });
}};
like that right?
see if that works
nope
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 });
}
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 });
}}
Popular Topics: Interaction collectors - Basic message component collector
read more
check the guide on this it will help explain it better than i am
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
the guide shows this in the collector event. so try putting it in there and removing the filter
Ok
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
here is code, it says Interaction has already been acknowledged.
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
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
lovely
im glad i could help
Have a good one!
thanks you as well
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
Id is prolly wrong
ye i realized that just now haha
here is my code: https://pastebin.com/m5RNPQB3
its not disabling the buttons
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
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
@frank meadow hey are you able t help me with something else?
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 !