setTimeout with an async function

Hello, I'm currently trying to use a setTimeout function to wait for an interaction from the user, and if it doesn't receive it in time, remove the interactable components from the message. So, I have something like
async removeComponents(message) {
await message.edit({content: "Timeout"})
}

async someOtherFunction() {
const timeout = setTimeout(removeComponents(message), 120000)

async removeComponents(message) {
await message.edit({content: "Timeout"})
}

async someOtherFunction() {
const timeout = setTimeout(removeComponents(message), 120000)

This, however, gives me the error that
The "callback" argument must be of type function. Received an instance of Promise
The "callback" argument must be of type function. Received an instance of Promise
If I instead do
const timeout = setTimeout(await removeComponents, 120000)
const timeout = setTimeout(await removeComponents, 120000)
I receive
The "callback" argument must be of type function. Received a undefined.
The "callback" argument must be of type function. Received a undefined.
What can I do to get around this / what have other people done when trying to remove interactions after a certain amount of time?
2 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Tyranasaurus
TyranasaurusOP3y ago
yeah this was me paraphrasing my function, I actually do this
async function removeInteractions(message, embed) {
await message.edit({
embeds: [embed],
components: [],
});
}
async function removeInteractions(message, embed) {
await message.edit({
embeds: [embed],
components: [],
});
}
How am I meant to correctly use it? Ah yes, thank you! yeah, I did - typo oops My error got buried under some debugging so I just typed it out This worked, thank you so much!
Want results from more Discord servers?
Add your server