-1

idk what is wrong but there are no errors nor is it send to the channel. any help would be great

  client.on('message', async message => {
    const channelName = "logs";
    // Create an embed.
    const msglogEmbed = new EmbedBuilder()
      .setTitle('Message Log')
      .setDescription(`${message.author.tag}: ${message.content}`)
      .setTimestamp(message.createdAt);
  
    // Get the channel by name.
    const channel = client.channels.cache.get(channelName);
  
    // Send the embed to the specified channel.
    await channel.send({ embeds: [msglogEmbed] });
  
    // Console log the message.
    console.log(`Message logged to channel ${channelName}`);
  });

  • 1
    Does this answer your question? [message.content doesn't have any value in Discord.js](https://stackoverflow.com/questions/73036854/message-content-doesnt-have-any-value-in-discord-js) – Zsolt Meszaros Jul 28 '23 at 23:19
  • Try using channel id and Channel.get instead and make sure you have the needed intents – NoobDev Jul 30 '23 at 11:00

1 Answers1

-1

You cannot get channels by their names. You need to use their channel IDs.

const channelId = "1122334455667788";

// Get the channel by ID.
const channel = client.channels.cache.get(channelId);

Alternatively, you can search for a channel by its name.

const channelName = "logs";

// Get the channel by Name.
const channel = client.channels.cache.find(c => c.name === channelName).first();
Darshan B
  • 658
  • 1
  • 5
  • 19