#Button for Specific User
86 messages · Page 1 of 1 (latest)
you can have a collector filter or if statement in the collector that checks if the i.user.id is equal to the message.author.id
this is my first time working with buttons so i really dont know how to doo that
here's an example of a filter you can use
const collectorFilter = async i => {
if (i.user.id !== message.author.id) {
await i.reply({ content: 'This is not for you.', ephemeral: true })
}
} // then in your collector options, use { filter: collectorFilter }
so my collector would look like this
const Collector = Reply.createMessageComponentCollector({
filter: collectorFilter
});```
nd then this would be above that? js const collectorFilter = i => { if (i.user.id !== message.author.id) { await i.reply({ content: 'This is not for you.', ephemeral: true }) } }
sure
?
whoops i forgot to make it async lol thats on me
sorry about that
ur good
so it kinda works, i cant roll it but another person rolls it and it says this is not for you
that's what you wanted right?
yeah but when the correct person clicks on the button i want it to work lol
that was my 8ball game and i clicked on it
didnt work
but when it click on someone elses game it says its not my game (which works and is correct)
are there any errors?
i noticed you dont have a time set for the collector. are you not looking for it to be temporary?
no errors
mm idk? ive never heard that i needed a time
collectors are meant to be temporary. if you want that button to be functional all the time then you should respond directly in the interactionCreate event
Message Components: The Client#interactionCreate event
Third and finally, you may wish to have a listener setup to respond to permanent button or select menu features of your guild. For this, returning to the Client#event:interactionCreateopen in new window event is the best approach.
read more
oh okay ill add a time limit of 10,000ms
but how can i fix this?
right above that if statement, do console.log(i)
in the future, it would be better to ask in the discord.js support channels for discord.js-related questions
did you log i?
lemme try
it logged nothing
where did you put the console.log
Collector.on("collect", async (i) => {
console.log(i);
if (i.customId === "8ball") {
return await i.update({ embeds: [AnswerEmbed], components: [] });
}
});```
you get no console output?
nope
are you clicking the button
well yeah lmfao
okay well it would appear that the collector isn't running at all
log Collector
If you aren't getting any errors, try to place console.log checkpoints throughout your code to find out where execution stops.
- Once you do, log relevant values and if-conditions
- More sophisticated debugging methods are breakpoints and runtime inspections: learn more
i logged it
nothing
thats why its failing
is the message even being sent?
no
okay... is your bot even online
it looks like this when it fails
...
how would it send the message if it wasnt online
you said the message wasnt sent though so thats why i asked, but it would appear that it is sending
ohh i thought u ment the answer embed
no, but thats okay.
please log Reply
okay i got collector to log
okay
i dont need you to do that anymore
i dont really believe that you need this return here so only have await i.update(...) and see what happens
i have that there
channelId: '1094499496471318528',
guildId: '1006727521166970900',
id: '1129584470647914588',
createdTimestamp: 1689384324467,
type: 0,
system: false,
content: '',
author: ClientUser {
id: '1091829957614899290',
bot: true,
system: false,
flags: UserFlagsBitField { bitfield: 0 },
username: 'Impresso Espresso',
discriminator: '9634',
avatar: '8dfce8ea80710f693f2cc8404fe4d5bd',
banner: null,
accentColor: null,
verified: true,
mfaEnabled: true
},
pinned: false,
tts: false,
nonce: null,
embeds: [ Embed { data: [Object] } ],
components: [ ActionRow { data: [Object], components: [Array] } ],
attachments: Collection(0) [Map] {},
stickers: Collection(0) [Map] {},
position: null,
roleSubscriptionData: null,
editedTimestamp: null,
reactions: ReactionManager { message: [Circular *1] },
mentions: MessageMentions {
everyone: false,
users: Collection(0) [Map] {},
roles: Collection(0) [Map] {},
_members: null,
_channels: null,
_parsedUsers: null,
crosspostedChannels: Collection(0) [Map] {},
repliedUser: null
},
webhookId: null,
groupActivityApplication: null,
applicationId: null,
activity: null,
flags: MessageFlagsBitField { bitfield: 0 },
reference: null,
interaction: null
}```
you removed that return ?
yes and heres my script
if (!args[0]) return message.reply({ embeds: [Fail] });
const Reply = await message.channel.send({ embeds: [QuestionEmbed], components: [Button] });
const CollectorFilter = async i => {
if (i.user.id !== message.author.id) {
await i.reply({ embeds: [NotYourButton], ephemeral: true });
}
}
const Collector = Reply.createMessageComponentCollector({
componentType: ComponentType.Button,
filter: CollectorFilter,
time: 10000
});
Collector.on("collect", async (i) => {
if (i.customId === "8ball") {
await i.update({ embeds: [AnswerEmbed], components: [] });
}
});
};```
alright and clicking the button still isnt updating the message?
nope
it says this intercation failed
are there any errors with that?
i have a feeling it's taking more than 3 seconds to respond
no errors! im so confuseddd
try this
- await i.update({ embeds: [AnswerEmbed], components: [] });
+ await i.deferUpdate();
+ await i.editReply({ embeds: [AnswerEmbed], components: [] });
i just changed that
heres my stuff
it didnt log anything so why would ur new script work
okay the filter might be causing some conflicts here, but it really shouldn't
i want you to use this instead and try it
const reply = await message.channel.send({ embeds: [QuestionEmbed], components: [Button] });
const collector = reply.createMessageComponentCollector({
componentType: ComponentType.Button,
time: 10000
});
collector.on("collect", async (i) => {
if (i.user.id === message.author.id) {
if (i.customId === "8ball") {
await i.update({ embeds: [AnswerEmbed], components: [] });
}
} else {
await i.reply({ embeds: [NotYourButton], ephemeral: true });
}
});
this removes the filter and checks inside the collect event instead
it's better practice to use lowercase names for variables since uppercase names can sometimes conflict with other Structures from packages
Message Components: Component collectors
read more
@trail harbor
error
i added an extra bracket on accident. you should be able to fix syntax errors very easily though
lemme see if it works
@trail harborit wasnt working for a bit but i had to change some stuff and it worked