I want my bot to read DM messages only and send them to a discord channel, but my code spam the message infinitely, spamming 5 times and then it pauses for a few seconds then spam again, also the bot don't read only DM messages and reads also guild messages so if I send anything in the guild it spams the content.
What do I want? If someone sends 'Hello!' (message content) to the bot in DM, the bot needs to send 'Hello!' (message content) to the specified channel (logs channel).
const Discord = require("discord.js");
const client = new Discord.Client({ intents:['DIRECT_MESSAGES'],
partials: ['MESSAGE'] });
client.on('ready', () =>{
console.log('Bot Online!'); //bot successfully logged in
});
client.on('message', async (message) => {
await client.channels.cache.get('CHANNEL ID').send(message.content);
console.log(message.content); //log messages
return;
});
// Authorizing
client.login('LOGIN');