So here is my code
const Discord = require('discord.js');
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [4611] });
let targetChannel = '906686653874176090' //target channel
client.once('ready', () => {
console.log('Ready! - Made By Woodington');
});
client.on('messageCreate', gotMessage);
function gotMessage(msg) {
if (msg.channel.id !== targetChannel) {
client.channels.fetch(targetChannel)
.then(channel => channel.send(msg.content `${client.user.tag}`))
.catch(console.error);
}
}
What it does is forward messages to another channel, with the users Discord tag at the bottom. However, it sends the bots Discord name and not the original senders. Any ideas?
CodePudding user response:
You are using the client
variable which is your own bot. You need to make use of the msg
parameter you received within the event. That's the reason why your bot sends its own tag, because client.user.tag
equals YourBot#0000
.
To send the author's tag, replace client.user.tag
with the following:
msg.author.tag
This will return Author's Username#0000