discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.36k stars 3.97k forks source link

Message won't send in channel #7381

Closed dubfib closed 2 years ago

dubfib commented 2 years ago

Which package is this bug report for?

discord.js

Issue description

  1. Create a file index.ts
  2. Import TextChannel from discord.js
  3. Create an embed
  4. Try to send a message to the channel const channel = client.channels.cache.get("937447927671058443") as TextChannel; channel.send({ embeds: [ embed ]});

Code sample

//Filtering out messages only to guild.
  if (!msg.startsWith("Guild > " || !msg.startsWith("From") || !msg.startsWith("Friend > "))) return;

  //Logging the messages in guild-chat channel for now.
  const channel = client.channels.cache.get("937447927671058443") as TextChannel;

  //console.log(channel);

  const mcEmbed = new DiscordJS.MessageEmbed()
  .setAuthor({ name: username, iconURL: `https://mc-heads.net/avatar/${username}` })
  .setDescription(`\`\`\`${msg}\`\`\``)
  channel.send({ embeds: [mcEmbed]});

  console.log(`Minecraft > ${username}: ${message}`);

Package version

13.6.0

Node.js version

Node: 16.13.2 Typescript: 4.5.5

Operating system

2022-1 Windows 11

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

Guilds, GuildMessages, GuildMessageReactions

I have tested this issue on a development release

13.6.0

dubfib commented 2 years ago

I tried on dev version but broke all my code including MessageEmbed, Intents

ImRodry commented 2 years ago

And the error is...? Also 13.6.0 is not a development release

dubfib commented 2 years ago

And the error is...? Also 13.6.0 is not a development release

I tried dev on 14.0.0-dev.1643544396.388f535 and a lot of errors came with it

image
ImRodry commented 2 years ago

That's because of the breaking changes included in v14. I was asking for the error you got when using that code above

dubfib commented 2 years ago

That's because of the breaking changes included in v14. I was asking for the error you got when using that code above

I get zero errors though.

ImRodry commented 2 years ago

Then why did you submit a bug report? If that code isn't being executed that's clearly not a problem with discord.js

dubfib commented 2 years ago

All the code is being executed including my command handler that works

ImRodry commented 2 years ago

If you can't send an error and the message isn't being sent then the code isn't reaching that point. Please close this issue and use the Discord server for any questions you might have while using the library.

If you want to know why the code isn't reaching that point, it's because of these lines, as no message in Minecraft starts with those strings since you need to include color codes image

dubfib commented 2 years ago

Its supposed to filter only guild chat messages. I also went to the discord and they said they don't know what to do.