How to make a filter?

const filter = (interaction) => {
interaction.user.id === interaction.author.id;
return
}

const collector = reply.createMessageComponentCollector({
ComponentType: ComponentType.Button,
filter,
time: 100_000,
});
const filter = (interaction) => {
interaction.user.id === interaction.author.id;
return
}

const collector = reply.createMessageComponentCollector({
ComponentType: ComponentType.Button,
filter,
time: 100_000,
});
Error: TypeError: Cannot read properties of undefined (reading 'id') How do I get the author Id? I tried researching...
12 Replies
d.js toolkit
d.js toolkit14mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
duck
duck14mo ago
you seem to already be aware that <Interaction>.user exists consider using the property that exists rather than one that doesn't though you should probably also rename your filter's param so that you don't attempt to compare the same interaction's user with itself
Nightro-Fx
Nightro-FxOP14mo ago
@duck I tried message.author.id but it failed even though I defined it...
Spam
Spam14mo ago
interaction.author ain't a thing
Nightro-Fx
Nightro-FxOP14mo ago
I also tried message.author.id but it didn't work.... Maybe save the id of the author in a variable before setting a filter
Spam
Spam14mo ago
dont use {} then ig
const filter = (interaction) => interaction.user.id === /* message author id. you handle this */;
const filter = (interaction) => interaction.user.id === /* message author id. you handle this */;
it's because you're checking for a boolean but not returning anything
Nightro-Fx
Nightro-FxOP14mo ago
@Andrew okay I will try that did they completely remove message.autor.id in v14?
Spam
Spam14mo ago
no they didn't, and there's no good reason to do so. I'm just telling you to handle it yourself because interaction.author isn't a thing
Nightro-Fx
Nightro-FxOP14mo ago
@Andrew Yes Ik just make an empty attempt because the message.author.id didn't work (this is in a command handler) Anyways, I'll try an handle it but thank you
duck
duck14mo ago
to fully elaborate, just naming the variable message won't suddenly make its value a Message object given your error and initial code, I'm assuming this is slash command handler (or in general an application command handler) rather than a text command handler, in which case this uses the interactionCreate event and therefore the object you're working with is an Interaction object as previously mentioned <Interaction>.user exists, which is a property you already seem aware of being the user who invoked the interaction
Nightro-Fx
Nightro-FxOP14mo ago
Oh I am using a splash command Oh Guys, I wasn't able to figure out the filter but I was able to find an alternative
const author = interaction.user.id // Define this when the author runs the command
const collector = reply.createMessageComponentCollector({
ComponentType: ComponentType.Button,
time: 100_000,
});

collector.on('collect', (interaction) => {
if (interaction.customId === 'cancel' && interaction.user.id === author) {
console.log('cancel succesful')
interaction.reply('canceled')
return
} else {
console.log('Error, Someone else tried to execute it.')
}
})
collector.on('end', () => {
confirm.setDisabled(true)
cancel.setDisabled(true)
reply.edit({
content: `Your request has expired, Please request another contract!`,
components: [buttonRow],
})
})
const author = interaction.user.id // Define this when the author runs the command
const collector = reply.createMessageComponentCollector({
ComponentType: ComponentType.Button,
time: 100_000,
});

collector.on('collect', (interaction) => {
if (interaction.customId === 'cancel' && interaction.user.id === author) {
console.log('cancel succesful')
interaction.reply('canceled')
return
} else {
console.log('Error, Someone else tried to execute it.')
}
})
collector.on('end', () => {
confirm.setDisabled(true)
cancel.setDisabled(true)
reply.edit({
content: `Your request has expired, Please request another contract!`,
components: [buttonRow],
})
})
I just defined the author by interaction.user.id right when the author requests the buttons and compare it when the button is clicked
Spam
Spam14mo ago
why would author be an id
Want results from more Discord servers?
Add your server