Creating a MessageComponentCollector in a function separate to the base command

To clean up a bit of code, I'm trying to send a couple collectors to a function in a different class. As is, my code creates an embed with a set of buttons, then attempts to run the channel.createMessageComponentCollector function. This works as intended in the base command, but doesn't work at all on the function I am delegating this to. The stacktrace:
classes/setup.ts:40:29 - error TS2339: Property 'createMessageComponentCollector' does not exist on type 'Channel'.

40 const collector = channel.createMessageComponentCollector({
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

at createTSError (/mnt/c/Users/Erik/Documents/Retool/node_modules/ts-node/src/index.ts:859:12)
at reportTSError (/mnt/c/Users/Erik/Documents/Retool/node_modules/ts-node/src/index.ts:863:19)
at getOutput (/mnt/c/Users/Erik/Documents/Retool/node_modules/ts-node/src/index.ts:1077:36)
at Object.compile (/mnt/c/Users/Erik/Documents/Retool/node_modules/ts-node/src/index.ts:1433:41)
at Module.m._compile (/mnt/c/Users/Erik/Documents/Retool/node_modules/ts-node/src/index.ts:1617:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Object.require.extensions.<computed> [as .ts] (/mnt/c/Users/Erik/Documents/Retool/node_modules/ts-node/src/index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
diagnosticCodes: [ 2339 ]
}
[nodemon] app crashed - waiting for file changes before starting...
classes/setup.ts:40:29 - error TS2339: Property 'createMessageComponentCollector' does not exist on type 'Channel'.

40 const collector = channel.createMessageComponentCollector({
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

at createTSError (/mnt/c/Users/Erik/Documents/Retool/node_modules/ts-node/src/index.ts:859:12)
at reportTSError (/mnt/c/Users/Erik/Documents/Retool/node_modules/ts-node/src/index.ts:863:19)
at getOutput (/mnt/c/Users/Erik/Documents/Retool/node_modules/ts-node/src/index.ts:1077:36)
at Object.compile (/mnt/c/Users/Erik/Documents/Retool/node_modules/ts-node/src/index.ts:1433:41)
at Module.m._compile (/mnt/c/Users/Erik/Documents/Retool/node_modules/ts-node/src/index.ts:1617:30)
at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Object.require.extensions.<computed> [as .ts] (/mnt/c/Users/Erik/Documents/Retool/node_modules/ts-node/src/index.ts:1621:12)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19) {
diagnosticCodes: [ 2339 ]
}
[nodemon] app crashed - waiting for file changes before starting...
Command code (Note, using WOKCommands for this part, though it should be irrelevant to this problem.):
export default {
category: 'Configuration',
description: 'Creates all necessary roles, emoji, and channels for the bot to function.',

slash: 'both',
testOnly: true, // This only works for test servers!

callback: async ({ interaction: msgInt, channel }) => {
Setup.createEmbed('setupType', msgInt, channel);
},
} as ICommand
export default {
category: 'Configuration',
description: 'Creates all necessary roles, emoji, and channels for the bot to function.',

slash: 'both',
testOnly: true, // This only works for test servers!

callback: async ({ interaction: msgInt, channel }) => {
Setup.createEmbed('setupType', msgInt, channel);
},
} as ICommand
Function code:
export default class Setup {

static async createEmbed (id: string, msgInt: CommandInteraction, channel: Channel) {
if (!setupSteps) return;

// Find the setup assigned with the sent ID
const currentSetup = setupSteps.find(x => x.id === id);
if (!currentSetup) return;

// Setup default colour
currentSetup.embed.color = 0xff00a2;

// Create action components
let actionComponents = []
for (let component of currentSetup.components) {
actionComponents.push(new MessageButton()
.setCustomId(component.id)
.setLabel(component.label)
.setStyle(component.style as MessageButtonStyleResolvable)
.setDisabled(component.disabled)
);
}

// TO-DO: Support multiple rows
const row = new MessageActionRow().addComponents(actionComponents)

// Send the embed
let sentReply = msgInt.reply({
embeds: [currentSetup.embed],
components: [row]
})

// Create a collector
const collector = channel.createMessageComponentCollector({
max: 1,
time: 1000 * 15,
})

// TO-DO: Add a listener to the collector
/*
collector.on('collect', (i: ButtonInteraction) => {
// blah blah
})
*/
return sentReply;
}
}
export default class Setup {

static async createEmbed (id: string, msgInt: CommandInteraction, channel: Channel) {
if (!setupSteps) return;

// Find the setup assigned with the sent ID
const currentSetup = setupSteps.find(x => x.id === id);
if (!currentSetup) return;

// Setup default colour
currentSetup.embed.color = 0xff00a2;

// Create action components
let actionComponents = []
for (let component of currentSetup.components) {
actionComponents.push(new MessageButton()
.setCustomId(component.id)
.setLabel(component.label)
.setStyle(component.style as MessageButtonStyleResolvable)
.setDisabled(component.disabled)
);
}

// TO-DO: Support multiple rows
const row = new MessageActionRow().addComponents(actionComponents)

// Send the embed
let sentReply = msgInt.reply({
embeds: [currentSetup.embed],
components: [row]
})

// Create a collector
const collector = channel.createMessageComponentCollector({
max: 1,
time: 1000 * 15,
})

// TO-DO: Add a listener to the collector
/*
collector.on('collect', (i: ButtonInteraction) => {
// blah blah
})
*/
return sentReply;
}
}
2 Replies
d.js docs
d.js docs2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
monbrey
monbrey2y ago
Its a typings issue Channel is too broad, it should be a TextChannel probably