Using Slash Command to send a message in a different chat and I want to capture the response

Hey I have this code that once a process is finished I'll notify the result in a different channel and I want to collect the first response of this other channel to continue to another step. How to await for the response and store the data?
if (notify) {
client.channels.fetch(cat.channel).then(channel => {
channel.send({
content: `:megaphone: **New update!**\n\n${cat.emoji} [${cat.name}] ${map.author} - ${map.code} - ${status.description}\n${map.picture}`
})
});
}
if (notify) {
client.channels.fetch(cat.channel).then(channel => {
channel.send({
content: `:megaphone: **New update!**\n\n${cat.emoji} [${cat.name}] ${map.author} - ${map.code} - ${status.description}\n${map.picture}`
})
});
}
5 Replies
d.js toolkit
d.js toolkit•4mo 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! - ✅ Marked as resolved by OP
Ikke
Ikke•4mo ago
TÆMBØØ
TÆMBØØ•4mo ago
Create a variable from the returned (and awaited) value of channel.send()
d.js docs
d.js docs•4mo ago
:method: TextChannel#send @14.15.3 Sends a message to this channel.
// Send a basic message
channel.send('hello!')
.then(message => console.log(`Sent message: ${message.content}`))
.catch(console.error);
// Send a basic message
channel.send('hello!')
.then(message => console.log(`Sent message: ${message.content}`))
.catch(console.error);
:method: TextChannel#awaitMessages @14.15.3 Similar to createMessageCollector but in promise form. Resolves with a collection of messages that pass the specified filter.
// Await !vote messages
const filter = m => m.content.startsWith('!vote');
// Errors: ['time'] treats ending because of the time limit as an error
channel.awaitMessages({ filter, max: 4, time: 60_000, errors: ['time'] })
.then(collected => console.log(collected.size))
.catch(collected => console.log(`After a minute, only ${collected.size} out of 4 voted.`));
// Await !vote messages
const filter = m => m.content.startsWith('!vote');
// Errors: ['time'] treats ending because of the time limit as an error
channel.awaitMessages({ filter, max: 4, time: 60_000, errors: ['time'] })
.then(collected => console.log(collected.size))
.catch(collected => console.log(`After a minute, only ${collected.size} out of 4 voted.`));
Ikke
Ikke•4mo ago
gonna test it guys, thank you it worked @Qjuh, thanks a lot
const commandChannel = await client.channels.fetch(command);
await commandChannel.send({
content: `%xero ${code}`
});

const filter = m => m.content.includes(code);

const collectedMapInfo = await commandChannel.awaitMessages({ filter, max: 1, time: 20_000, errors: ['time'] });

if (!collectedMapInfo) {
await interaction.editReply({ content: `Oops! Something went wront. Time out trying to get Map Info from Sharpiebot`, ephemeral: true });
return;
}
const commandChannel = await client.channels.fetch(command);
await commandChannel.send({
content: `%xero ${code}`
});

const filter = m => m.content.includes(code);

const collectedMapInfo = await commandChannel.awaitMessages({ filter, max: 1, time: 20_000, errors: ['time'] });

if (!collectedMapInfo) {
await interaction.editReply({ content: `Oops! Something went wront. Time out trying to get Map Info from Sharpiebot`, ephemeral: true });
return;
}
Want results from more Discord servers?
Add your server