Detecting Application Commands Intended for Other Bots!

I'm currently working on a Discord.js bot where I need to detect when users trigger application commands intended for other bots. I want to be able to track when a user sends a command like "/play" meant for a music bot, and then capture the interaction where the music bot responds. Example: a user types "/play", thinking it will trigger the music bot, but my bot intercepts it and logs that it was intended for the music bot. Then, when the music bot responds to the user's command, my bot should detect this interaction and log that the music bot replied, possibly with additional details such as an embed containing a link. My question is: Is it possible to achieve this functionality with Discord.js, and if so, how can I implement it effectively? What I've tried:
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return; // Ignore if not a slash command

// Check if the command is "/play"
if (interaction.commandName === 'play') {
// Log that the /play command was detected for the music bot
console.log("Detected /play command meant for music bot.");

// Check if the music bot responds with an embed containing a link
const filter = (response) => {
return response.author.id === '123456789012345678' && response.embeds.length && response.embeds[0].title === "Music Bot Response" && response.embeds[0].description === "Here is your requested song: [Song Title](songlink)";
};

interaction.channel.awaitMessages({ filter, max: 1, time: 10000, errors: ['time'] })
.then(async (collected) => {
console.log("Detected music bot replied with an embed containing a link.");

// logic for handling the music bot's response
})
.catch((error) => {
console.error('Error while waiting for music bot response:', error);
});
}
});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isCommand()) return; // Ignore if not a slash command

// Check if the command is "/play"
if (interaction.commandName === 'play') {
// Log that the /play command was detected for the music bot
console.log("Detected /play command meant for music bot.");

// Check if the music bot responds with an embed containing a link
const filter = (response) => {
return response.author.id === '123456789012345678' && response.embeds.length && response.embeds[0].title === "Music Bot Response" && response.embeds[0].description === "Here is your requested song: [Song Title](songlink)";
};

interaction.channel.awaitMessages({ filter, max: 1, time: 10000, errors: ['time'] })
.then(async (collected) => {
console.log("Detected music bot replied with an embed containing a link.");

// logic for handling the music bot's response
})
.catch((error) => {
console.error('Error while waiting for music bot response:', error);
});
}
});
4 Replies
d.js toolkit
d.js toolkit8mo 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
smokey ♱
smokey ♱OP8mo ago
Detecting the public reply of the bot shouldn't be any different than detecting a regular users message or is there anything special I should be aware of?
Zerls
Zerls8mo ago
you can use Message.interaction however this is to detect a user using a command of that bot
smokey ♱
smokey ♱OP8mo ago
ookay I'll try that thanks for the help!
Want results from more Discord servers?
Add your server