'Adding Username of person who sent DM to bot to display with their message
New to JS as you can probably tell. Trying to make a discord bot that forwards its DM's to a channel on my discord. Currently it works, sends whatever content it is sent via DM to a specific channel ID and replies "Thanks!" to the DM sender. What code do I need to add so that it would read and send the senders "Username" and then the "Message Content" together to the DC channel? Thank you
const { Client, Intents } = require('discord.js');
// Initializing your client
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Intents.FLAGS.GUILD_MESSAGE_TYPING,
Intents.FLAGS.DIRECT_MESSAGES,
Intents.FLAGS.DIRECT_MESSAGE_REACTIONS,
Intents.FLAGS.DIRECT_MESSAGE_TYPING,
],
partials: [
'CHANNEL',
]
});
client.on('message', async (message) => {
if(message.author.bot) return;
if(message.guild) return;
await client.channels.cache.get('DISCORD_CH_ID').send(message.content);
console.log(message.content);
message.author.send("Thanks")
return;
});
client.login('TOKEN');
Solution 1:[1]
I think this is what you're asking:
await client.channels.cache.get('DISCORD_CH_ID').send(`${message.author.username}: ${message.content}`);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ben |
