Creating a Discord bot to forward DMs and enable admin replies

Hey everyone! I’m trying to set up a Discord bot using discord.js v13 that can do two main things:

  1. Catch all direct messages sent to the bot and forward them to a webhook
  2. Allow an admin to reply to these messages using a command

I’m not sure how to get started with this. Has anyone done something similar before? I’d really appreciate some guidance on how to set this up.

Here’s a basic outline of what I’m thinking:

const Discord = require('discord.js');
const client = new Discord.Client();

client.on('messageCreate', (message) => {
  if (message.channel.type === 'DM') {
    // Forward message to webhook
  }
});

client.on('interactionCreate', (interaction) => {
  if (interaction.commandName === 'respond') {
    // Send admin's response back to the original user
  }
});

client.login('BOT_TOKEN');

Any tips or code snippets would be super helpful! Thanks in advance!

I’ve implemented a similar system for my community server. Here’s what worked for me:

For forwarding DMs, you’ll want to create a new webhook in your admin channel. Then in your messageCreate event, check if it’s a DM and use the webhook to send the message content along with the user’s ID and username.

For admin replies, I’d suggest using a slash command like ‘/reply’. In the command handler, fetch the user with the provided ID, then use user.send() to DM them back.

One tip: store the original message ID when forwarding, so you can create threaded responses in your admin channel. This helps keep conversations organized.

Also, consider adding some basic spam protection - maybe a cooldown on DMs to prevent abuse. Good luck with your project!

yo adventuroushiker17, i’ve done similar before. for forwarding DMs, use the webhook.send() method in ur messageCreate event. for admin replies, create a slash command that takes the user ID and message as params. then use client.users.fetch(userId) to get the user and send the reply. lmk if more help needed!

I’ve implemented a similar bot for our community Discord. Here’s what worked well:

For DM forwarding, create a webhook in your admin channel. In the messageCreate event, check for DMs and use webhook.send() to forward the message, user ID, and username.

For admin replies, implement a slash command like ‘/reply’ with user ID and message parameters. Use client.users.fetch(userId) to get the user object, then user.send() to DM the reply.

Consider adding message IDs to forwarded messages for threading in the admin channel. This helps organize conversations.

Remember to implement rate limiting on DMs to prevent spam. Also, ensure proper error handling for cases where users have DMs closed or have left the server.