My collector isn't triggering, but is being created. There are no errors in console.

Hello everyone. I have a slash command script that allows people to host giveaways in a local boardgame club I am a part of. In my script I have two button interaction collectors. The first one to trigger is to confirm that the person has read the rules that show up on an embed. This collector works great. The second collector that triggers is for when someone inputs a date that does not follow the regex in the script to error check before sending the message. This collector gets created properly (I think) but does not see any button presses, and I am not sure why. The collector I am having issues with is created on line 28. My script: https://pastebin.com/J84GRdH8 There are no errors, no stack traces, and no promise rejections. I am running 14.17.3 D.js and node 20.11.1.
Pastebin
giveaway.js - Pastebin.com
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.
10 Replies
d.js toolkit
d.js toolkit2mo 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!
NyR
NyR2mo ago
Pass fetchReply: true to your reply options Alternatively, the better option is using withResponse: true if you have latest d.js which will return InteractionCallbackResponse, which returns the created message, so you can do <response>.resources.message.createMessageComponentCollector() Also await is useless there
d.js docs
d.js docs2mo ago
:class: InteractionCallbackResponse [email protected] Represents an interaction's response :property: InteractionCallbackResponse#resource [email protected] The resource that was created by the interaction response
BoxWithout
BoxWithoutOP2mo ago
So I got it to work with fetchReply: true, but I am confused by the better options. Heres what lines 25 and 28 look like now:
const retryMessage = interaction.reply({ content: 'The date you entered is not in the correct format. Please click the button to try again.', components: [actionRow], withResponse: true, flags: MessageFlags.Ephemeral });

const retryCollector = await retryMessage.resources.message.createMessageCollector({ componentType: ComponentType.Button, time: 1000 * 60 * 3 });
const retryMessage = interaction.reply({ content: 'The date you entered is not in the correct format. Please click the button to try again.', components: [actionRow], withResponse: true, flags: MessageFlags.Ephemeral });

const retryCollector = await retryMessage.resources.message.createMessageCollector({ componentType: ComponentType.Button, time: 1000 * 60 * 3 });
I am not sure why this is better, either. Is it just because fetchReply is deprecated?
NyR
NyR2mo ago
Yes, it'll be removed in v15, that should work
BoxWithout
BoxWithoutOP2mo ago
I am getting the error: TypeError: Cannot read properties of undefined (reading 'message') The error is on line 28, or line 3 in that code block
NyR
NyR2mo ago
Can you log retryMessage ?
BoxWithout
BoxWithoutOP2mo ago
Yeah will do It returns a promise XD I am gonna put await back in and see what happens
NyR
NyR2mo ago
Oh right, yeah you need to resolve the promise, the await i was talking about is for creating the collector, it's not async
BoxWithout
BoxWithoutOP2mo ago
Oh right, good point. I am having trouble copying the error for whatever reason. Let me try doing it from bash instead of portainer
InteractionCallbackResponse {
interaction: InteractionCallback {
id: '1332761414464438313',
type: 5,
activityInstanceId: null,
responseMessageId: '1332761415119015987',
responseMessageLoading: false,
responseMessageEphemeral: true
},
resource: InteractionCallbackResource {
type: 4,
activityInstance: null,
message: Message {
channelId: '1206384509042298981',
guildId: '1206372423465832519',
id: '1332761415119015987',
createdTimestamp: 1737825482874,
type: 19,
system: false,
content: 'The date you entered is not in the correct format. Please click the button to try again.',
author: [ClientUser],
pinned: false,
tts: false,
nonce: '1332761408512720896',
embeds: [],
components: [Array],
attachments: Collection(0) [Map] {},
stickers: Collection(0) [Map] {},
position: 0,
roleSubscriptionData: null,
resolved: [Object],
editedTimestamp: null,
reactions: [ReactionManager],
mentions: [MessageMentions],
webhookId: '1182005992712572999',
groupActivityApplication: null,
applicationId: '1182005992712572999',
activity: null,
flags: [MessageFlagsBitField],
reference: [Object],
InteractionCallbackResponse {
interaction: InteractionCallback {
id: '1332761414464438313',
type: 5,
activityInstanceId: null,
responseMessageId: '1332761415119015987',
responseMessageLoading: false,
responseMessageEphemeral: true
},
resource: InteractionCallbackResource {
type: 4,
activityInstance: null,
message: Message {
channelId: '1206384509042298981',
guildId: '1206372423465832519',
id: '1332761415119015987',
createdTimestamp: 1737825482874,
type: 19,
system: false,
content: 'The date you entered is not in the correct format. Please click the button to try again.',
author: [ClientUser],
pinned: false,
tts: false,
nonce: '1332761408512720896',
embeds: [],
components: [Array],
attachments: Collection(0) [Map] {},
stickers: Collection(0) [Map] {},
position: 0,
roleSubscriptionData: null,
resolved: [Object],
editedTimestamp: null,
reactions: [ReactionManager],
mentions: [MessageMentions],
webhookId: '1182005992712572999',
groupActivityApplication: null,
applicationId: '1182005992712572999',
activity: null,
flags: [MessageFlagsBitField],
reference: [Object],
It's because it's resource not resources Also, it's createMessageComponentCollector() not createMessageCollector(). It's working now! Thank you for your help! I will remove the extra await XD

Did you find this page helpful?