Adding Interactive Buttons to Discord Bot Messages from Webhook

I’m working on a Discord bot that needs to respond to webhook messages. I have a webhook set up that sends messages to a channel when someone submits a Google form. What I want to do is make my bot automatically add buttons (like approve/reject) whenever it detects a message from this webhook.

I tried using the messagecreate event to catch bot messages and add buttons, but it’s not working. Here’s what I attempted:

client.on('messageCreate', (msg) => {
    if(msg.author.bot) {
        const approveBtn = new ButtonBuilder()
            .setLabel('Approve')
            .setStyle(ButtonStyle.Success)
            .setCustomId('approve_action');

        const rejectBtn = new ButtonBuilder()
            .setLabel('Reject')
            .setStyle(ButtonStyle.Secondary)
            .setCustomId('reject_action');

        const row = new ActionRowBuilder().addComponents(approveBtn, rejectBtn);
        msg.reply({content: 'Choose an action:', components: [row] });
    }
});

The buttons aren’t showing up at all. Am I missing something with how Discord handles webhook messages?

You’re hitting a common Discord webhook issue. Webhooks get processed differently than regular bot messages, so messageCreate events don’t always fire properly for them. I’ve dealt with this exact problem building approval systems. Try adding a small setTimeout delay before interacting with the webhook message - Discord needs time to fully process it. Also double-check your bot has SEND_MESSAGES and USE_EXTERNAL_EMOJIS permissions for that channel. First though, log the message author details to console and make sure the webhook message is actually being detected.

Your bot can’t reply to webhook messages with components - Discord handles webhook messages differently and throws an error when you use .reply() on them. Use msg.channel.send() instead of msg.reply() and you’re good to go. Just double-check your bot has permissions to send messages with components in that channel. Had this same issue last month and switching to channel.send fixed it right away.

yep, that’s a common issue. webhook messages don’t trigger the msgCreate event like normal ones do. try checking msg.webhookId or use the webhook’s username to filter them out. that should do the trick!