1

I'm trying to get the message content of the messages sent in my server and the bot only returns a blank character. Does anyone know how to fix this?

Code

client.on('messageCreate', async (message) => {
  console.log(message.content)
});

Message

enter image description here

Console print

enter image description here

Nepzerox
  • 35
  • 5
  • Where's your message.content string? You don't provide any string to make it as message. So it will literally going to be an empty strings (*invisible character*) – 新Acesyyy Oct 18 '22 at 00:52
  • Could this be a possible side affect from your client missing the message content intent? Make sure to enable the intent through your developer portal and include the bit in your client intents – Elitezen Oct 18 '22 at 00:58
  • Make sure you have message content intents enabled on your discord developers portal dashboard. – Pooyan Oct 18 '22 at 03:24
  • 1
    Does this answer your question? [message.content doesn't have any value in Discord.js v14](https://stackoverflow.com/questions/73036854/message-content-doesnt-have-any-value-in-discord-js-v14) – Zsolt Meszaros Oct 18 '22 at 04:26

2 Answers2

1

I'm not sure but I think you forgot to include the new MessageContent Intent.
You have to add it to the intents array on your Client instance like I have on mine:

my discord bot intents

RappyTV
  • 118
  • 7
  • 1
    Probably the answer, thanks for your help. After a little while it just started working (don't know why). Thanks for trying to help though! – Nepzerox Oct 20 '22 at 00:26
-1

Get your string on your discord server such as args[0] to get this method you can use const args first then use your message.content

client.on('messageCreate', async(message) => {
    const args = message.content.slice().trim().split(/\s+/);
    console.log(args[0]);
});

Sample given

You can also adjust it to get all of the word they say:

client.on('messageCreate', async(message) => {
    const args = message.content.slice().trim().split(/\s+/);
    console.log(args.splice(0).join(" "));
});

Sample Given2

新Acesyyy
  • 1,152
  • 1
  • 3
  • 22
  • If `message.content` is returning `""` how is slice, trim, and split supposed to affect it? – Elitezen Oct 18 '22 at 01:20
  • I'm also confused on what your answer is trying to solve. The OP is getting a blank response from `message.content`, which is the entire message string. Why are you splitting a string and getting the first index? – Elitezen Oct 18 '22 at 01:23
  • He can also remove it since I only copied it in to my prefix workout, Its not actually going to affect the `splice` – 新Acesyyy Oct 18 '22 at 01:23
  • He wanted to get the message thru discord, ofcourse I provided how he will going to get that string sing splice(0) to get all the words – 新Acesyyy Oct 18 '22 at 01:24
  • `message.content` *is the string* there's no need to manipulate the string and turn it into an array – Elitezen Oct 18 '22 at 01:25
  • Then why it got empty string? – 新Acesyyy Oct 18 '22 at 01:26
  • Because of `intents`? then why its working if its because the intents? – 新Acesyyy Oct 18 '22 at 01:27
  • [String.split](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split) will not magically give an empty string content. Creating args is a very DJS specific thing. – Elitezen Oct 18 '22 at 01:30
  • As I mentioned, OP can remove those 3, the main point here is to use *splice(0)* to replace the `invisible character` into the main `string given` – 新Acesyyy Oct 18 '22 at 01:32
  • I have all intents enabled through the dev panel and have my intents set to 32767 (enable all intents) - still isn't working – Nepzerox Oct 18 '22 at 20:06